1.8.0, merging Mono and Il2Cpp builds, adding BepInEx support

* Project renamed to Explorer to reflect the new scope
* Merged Mono and Il2Cpp builds
* Merged BepInEx and MelonLoader builds
* Some minor changes to accommodate for this
* The release DLL and the config file now use "Explorer" in place of "CppExplorer" for file and folder names
This commit is contained in:
sinaioutlander
2020-09-27 22:04:23 +10:00
parent 8c6202c194
commit b550356f14
47 changed files with 1230 additions and 523 deletions

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using MelonLoader;
namespace Explorer
{
@ -36,11 +35,11 @@ namespace Explorer
{
if (index < 0 || Pages.Count <= index)
{
MelonLogger.Log("cannot set page " + index);
ExplorerCore.Log("cannot set page " + index);
return;
}
m_currentPage = index;
GUI.BringWindowToFront(MainWindowID);
GUIUnstrip.BringWindowToFront(MainWindowID);
GUI.FocusWindow(MainWindowID);
}
@ -51,16 +50,16 @@ namespace Explorer
public void OnGUI()
{
MainRect = GUI.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, CppExplorer.NAME);
MainRect = GUIUnstrip.Window(MainWindowID, MainRect, (GUI.WindowFunction)MainWindow, ExplorerCore.NAME);
}
private void MainWindow(int id)
{
GUI.DragWindow(new Rect(0, 0, MainRect.width - 90, 20));
if (GUI.Button(new Rect(MainRect.width - 90, 2, 80, 20), $"Hide ({ModConfig.Instance.Main_Menu_Toggle})"))
if (GUIUnstrip.Button(new Rect(MainRect.width - 90, 2, 80, 20), $"Hide ({ModConfig.Instance.Main_Menu_Toggle})"))
{
CppExplorer.ShowMenu = false;
ExplorerCore.ShowMenu = false;
return;
}
@ -83,7 +82,7 @@ namespace Explorer
private void MainHeader()
{
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
for (int i = 0; i < Pages.Count; i++)
{
if (m_currentPage == i)
@ -91,22 +90,22 @@ namespace Explorer
else
GUI.color = Color.white;
if (GUILayout.Button(Pages[i].Name, null))
if (GUILayout.Button(Pages[i].Name, new GUILayoutOption[0]))
{
m_currentPage = i;
}
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUI.color = Color.white;
InspectUnderMouse.EnableInspect = GUILayout.Toggle(InspectUnderMouse.EnableInspect, "Inspect Under Mouse (Shift + RMB)", null);
InspectUnderMouse.EnableInspect = GUILayout.Toggle(InspectUnderMouse.EnableInspect, "Inspect Under Mouse (Shift + RMB)", new GUILayoutOption[0]);
bool mouseState = CursorControl.ForceUnlockMouse;
bool setMouse = GUILayout.Toggle(mouseState, "Force Unlock Mouse (Left Alt)", null);
bool setMouse = GUILayout.Toggle(mouseState, "Force Unlock Mouse (Left Alt)", new GUILayoutOption[0]);
if (setMouse != mouseState) CursorControl.ForceUnlockMouse = setMouse;
WindowManager.TabView = GUILayout.Toggle(WindowManager.TabView, "Tab View", null);
WindowManager.TabView = GUILayout.Toggle(WindowManager.TabView, "Tab View", new GUILayoutOption[0]);
GUILayout.EndHorizontal();
//GUIUnstrip.Space(10);

View File

@ -6,7 +6,9 @@ namespace Explorer
{
public class ReplHelper : MonoBehaviour
{
#if CPP
public ReplHelper(IntPtr intPtr) : base(intPtr) { }
#endif
public T Find<T>() where T : Object
{

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using MelonLoader;
using Mono.CSharp;
using UnityEngine;
@ -36,15 +35,16 @@ namespace Explorer
public override void Init()
{
#if CPP
UnhollowerRuntimeLib.ClassInjector.RegisterTypeInIl2Cpp<ReplHelper>();
#endif
try
{
MethodInput = @"// This is a basic C# console.
// Some common using directives are added by default, you can add more below.
// If you want to return some output, MelonLogger.Log() it.
// If you want to return some output, Debug.Log() it.
MelonLogger.Log(""hello world"");";
Debug.Log(""hello world"");";
ResetConsole();
@ -55,7 +55,7 @@ MelonLogger.Log(""hello world"");";
}
catch (Exception e)
{
MelonLogger.Log($"Error setting up console!\r\nMessage: {e.Message}");
ExplorerCore.Log($"Error setting up console!\r\nMessage: {e.Message}");
MainMenu.SetCurrentPage(0);
MainMenu.Pages.Remove(this);
}
@ -110,7 +110,7 @@ MelonLogger.Log(""hello world"");";
{
if (!suppressWarning)
{
MelonLogger.LogWarning(e.GetType() + ", " + e.Message);
ExplorerCore.LogWarning(e.GetType() + ", " + e.Message);
}
}
@ -120,19 +120,19 @@ MelonLogger.Log(""hello world"");";
public override void DrawWindow()
{
GUILayout.Label("<b><size=15><color=cyan>C# Console</color></size></b>", null);
GUILayout.Label("<b><size=15><color=cyan>C# Console</color></size></b>", new GUILayoutOption[0]);
GUI.skin.label.alignment = TextAnchor.UpperLeft;
GUILayout.Label("Enter code here as though it is a method body:", null);
GUILayout.Label("Enter code here as though it is a method body:", new GUILayoutOption[0]);
inputAreaScroll = GUIUnstrip.BeginScrollView(inputAreaScroll, new GUILayoutOption[] { GUILayout.Height(250) });
MethodInput = GUILayout.TextArea(MethodInput, new GUILayoutOption[] { GUILayout.ExpandHeight(true) });
MethodInput = GUIUnstrip.TextArea(MethodInput, new GUILayoutOption[] { GUILayout.ExpandHeight(true) });
GUIUnstrip.EndScrollView();
if (GUILayout.Button("<color=cyan><b>Execute</b></color>", null))
if (GUILayout.Button("<color=cyan><b>Execute</b></color>", new GUILayoutOption[0]))
{
try
{
@ -144,19 +144,19 @@ MelonLogger.Log(""hello world"");";
if (result != null && !Equals(result, VoidType.Value))
{
MelonLogger.Log("[Console Output]\r\n" + result.ToString());
ExplorerCore.Log("[Console Output]\r\n" + result.ToString());
}
}
}
catch (Exception e)
{
MelonLogger.LogError("Exception compiling!\r\nMessage: " + e.Message + "\r\nStack: " + e.StackTrace);
ExplorerCore.LogError("Exception compiling!\r\nMessage: " + e.Message + "\r\nStack: " + e.StackTrace);
}
}
GUILayout.Label("<b>Using directives:</b>", null);
GUILayout.Label("<b>Using directives:</b>", new GUILayoutOption[0]);
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUILayout.Label("Add namespace:", new GUILayoutOption[] { GUILayout.Width(105) });
UsingInput = GUILayout.TextField(UsingInput, new GUILayoutOption[] { GUILayout.Width(150) });
if (GUILayout.Button("<b><color=lime>Add</color></b>", new GUILayoutOption[] { GUILayout.Width(120) }))
@ -171,7 +171,7 @@ MelonLogger.Log(""hello world"");";
foreach (var asm in UsingDirectives)
{
GUILayout.Label(AsmToUsing(asm, true), null);
GUILayout.Label(AsmToUsing(asm, true), new GUILayoutOption[0]);
}
}

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MelonLoader;
using UnityEngine;
using UnityEngine.SceneManagement;
@ -87,7 +86,11 @@ namespace Explorer
foreach (var obj in Resources.FindObjectsOfTypeAll(ReflectionHelpers.GameObjectType))
{
#if CPP
var go = obj.TryCast<GameObject>();
#else
var go = obj as GameObject;
#endif
if (go.name.ToLower().Contains(_search.ToLower()) && go.scene.name == m_currentScene)
{
matches.Add(new GameObjectCache(go));
@ -125,14 +128,22 @@ namespace Explorer
{
try
{
var scene = SceneManager.GetSceneByName(m_currentScene);
for (int i = 0; i < SceneManager.sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
allTransforms.AddRange(scene.GetRootGameObjects()
.Select(it => it.transform));
if (scene.name == m_currentScene)
{
allTransforms.AddRange(scene.GetRootGameObjects()
.Select(it => it.transform));
break;
}
}
}
catch
{
MelonLogger.Log("Exception getting root scene objects, falling back to backup method...");
ExplorerCore.Log("Exception getting root scene objects, falling back to backup method...");
m_getRootObjectsFailed = true;
allTransforms.AddRange(GetRootObjectsManual_Impl());
@ -174,7 +185,11 @@ namespace Explorer
var list = new List<Transform>();
foreach (var obj in array)
{
#if CPP
var transform = obj.TryCast<Transform>();
#else
var transform = obj as Transform;
#endif
if (transform.parent == null && transform.gameObject.scene.name == m_currentScene)
{
list.Add(transform);
@ -184,7 +199,7 @@ namespace Explorer
}
catch (Exception e)
{
MelonLogger.Log("Exception getting root scene objects (manual): "
ExplorerCore.Log("Exception getting root scene objects (manual): "
+ e.GetType() + ", " + e.Message + "\r\n"
+ e.StackTrace);
return new Transform[0];
@ -199,7 +214,7 @@ namespace Explorer
{
DrawHeaderArea();
GUILayout.BeginVertical(GUI.skin.box, null);
GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null);
DrawPageButtons();
@ -222,20 +237,20 @@ namespace Explorer
private void DrawHeaderArea()
{
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
// Current Scene label
GUILayout.Label("Current Scene:", new GUILayoutOption[] { GUILayout.Width(120) });
SceneChangeButtons();
GUILayout.Label("<color=cyan>" + m_currentScene + "</color>", null); //new GUILayoutOption[] { GUILayout.Width(250) });
GUILayout.Label("<color=cyan>" + m_currentScene + "</color>", new GUILayoutOption[0]);
GUILayout.EndHorizontal();
// ----- GameObject Search -----
GUILayout.BeginHorizontal(GUI.skin.box, null);
GUILayout.BeginHorizontal(GUIContent.none, GUI.skin.box, null);
GUILayout.Label("<b>Search Scene:</b>", new GUILayoutOption[] { GUILayout.Width(100) });
m_searchInput = GUILayout.TextField(m_searchInput, null);
m_searchInput = GUILayout.TextField(m_searchInput, new GUILayoutOption[0]);
if (GUILayout.Button("Search", new GUILayoutOption[] { GUILayout.Width(80) }))
{
@ -248,8 +263,14 @@ namespace Explorer
private void SceneChangeButtons()
{
// Need to do 'ToList()' so the object isn't cleaned up by Il2Cpp GC.
var scenes = SceneManager.GetAllScenes().ToList();
var scenes = new List<Scene>();
var names = new List<string>();
for (int i = 0; i < SceneManager.sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
names.Add(scene.name);
scenes.Add(scene);
}
if (scenes.Count > 1)
{
@ -264,7 +285,7 @@ namespace Explorer
}
if (changeWanted != 0)
{
int index = scenes.IndexOf(SceneManager.GetSceneByName(m_currentScene));
int index = names.IndexOf(m_currentScene);
index += changeWanted;
if (index > scenes.Count - 1)
{
@ -281,7 +302,7 @@ namespace Explorer
private void DrawPageButtons()
{
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
Pages.DrawLimitInputArea();
@ -312,7 +333,7 @@ namespace Explorer
{
if (m_currentTransform != null)
{
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
if (GUILayout.Button("<-", new GUILayoutOption[] { GUILayout.Width(35) }))
{
TraverseUp();
@ -329,11 +350,11 @@ namespace Explorer
}
else
{
GUILayout.Label("Scene Root GameObjects:", null);
GUILayout.Label("Scene Root GameObjects:", new GUILayoutOption[0]);
if (m_getRootObjectsFailed)
{
if (GUILayout.Button("Update Root Object List (auto-update failed!)", null))
if (GUILayout.Button("Update Root Object List (auto-update failed!)", new GUILayoutOption[0]))
{
Update_Impl(true);
}
@ -358,7 +379,7 @@ namespace Explorer
}
label += "</i></color>";
GUILayout.Label(label, null);
GUILayout.Label(label, new GUILayoutOption[0]);
}
else
{
@ -381,7 +402,7 @@ namespace Explorer
CancelSearch();
}
GUILayout.Label("Search Results:", null);
GUILayout.Label("Search Results:", new GUILayoutOption[0]);
if (m_searchResults.Count > 0)
{
@ -403,13 +424,13 @@ namespace Explorer
}
else
{
GUILayout.Label("<i><color=red>Null or destroyed!</color></i>", null);
GUILayout.Label("<i><color=red>Null or destroyed!</color></i>", new GUILayoutOption[0]);
}
}
}
else
{
GUILayout.Label("<color=red><i>No results found!</i></color>", null);
GUILayout.Label("<color=red><i>No results found!</i></color>", new GUILayoutOption[0]);
}
}

View File

@ -3,7 +3,6 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using MelonLoader;
using UnityEngine;
namespace Explorer
@ -65,10 +64,17 @@ namespace Explorer
{
var toCache = obj;
#if CPP
if (toCache is Il2CppSystem.Object ilObject)
{
toCache = ilObject.TryCast<GameObject>() ?? ilObject.TryCast<Transform>()?.gameObject ?? ilObject;
}
#else
if (toCache is GameObject || toCache is Transform)
{
toCache = toCache as GameObject ?? (toCache as Transform).gameObject;
}
#endif
var cache = CacheObjectBase.GetCacheObject(toCache);
m_searchResults.Add(cache);
@ -83,7 +89,7 @@ namespace Explorer
try
{
// helpers
GUILayout.BeginHorizontal(GUI.skin.box, null);
GUILayout.BeginHorizontal(GUIContent.none, GUI.skin.box, null);
GUILayout.Label("<b><color=orange>Helpers</color></b>", new GUILayoutOption[] { GUILayout.Width(70) });
if (GUILayout.Button("Find Static Instances", new GUILayoutOption[] { GUILayout.Width(180) }))
{
@ -96,15 +102,15 @@ namespace Explorer
SearchBox();
// results
GUILayout.BeginVertical(GUI.skin.box, null);
GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null);
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label("<b><color=orange>Results </color></b>" + " (" + m_searchResults.Count + ")", null);
GUILayout.Label("<b><color=orange>Results </color></b>" + " (" + m_searchResults.Count + ")", new GUILayoutOption[0]);
GUI.skin.label.alignment = TextAnchor.UpperLeft;
int count = m_searchResults.Count;
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
Pages.DrawLimitInputArea();
@ -145,7 +151,7 @@ namespace Explorer
}
else
{
GUILayout.Label("<color=red><i>No results found!</i></color>", null);
GUILayout.Label("<color=red><i>No results found!</i></color>", new GUILayoutOption[0]);
}
GUIUnstrip.EndScrollView();
@ -159,21 +165,21 @@ namespace Explorer
private void SearchBox()
{
GUILayout.BeginVertical(GUI.skin.box, null);
GUILayout.BeginVertical(GUIContent.none, GUI.skin.box, null);
// ----- GameObject Search -----
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label("<b><color=orange>Search</color></b>", null);
GUILayout.Label("<b><color=orange>Search</color></b>", new GUILayoutOption[0]);
GUI.skin.label.alignment = TextAnchor.UpperLeft;
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUILayout.Label("Name Contains:", new GUILayoutOption[] { GUILayout.Width(100) });
m_searchInput = GUILayout.TextField(m_searchInput, new GUILayoutOption[] { GUILayout.Width(200) });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUILayout.Label("Class Filter:", new GUILayoutOption[] { GUILayout.Width(100) });
ClassFilterToggle(TypeFilter.Object, "Object");
@ -183,7 +189,7 @@ namespace Explorer
GUILayout.EndHorizontal();
if (TypeMode == TypeFilter.Custom)
{
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUI.skin.label.alignment = TextAnchor.MiddleRight;
GUILayout.Label("Custom Class:", new GUILayoutOption[] { GUILayout.Width(250) });
GUI.skin.label.alignment = TextAnchor.UpperLeft;
@ -191,7 +197,7 @@ namespace Explorer
GUILayout.EndHorizontal();
}
GUILayout.BeginHorizontal(null);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUILayout.Label("Scene Filter:", new GUILayoutOption[] { GUILayout.Width(100) });
SceneFilterToggle(SceneFilter.Any, "Any", 60);
SceneFilterToggle(SceneFilter.This, "This Scene", 100);
@ -199,7 +205,7 @@ namespace Explorer
SceneFilterToggle(SceneFilter.None, "No Scene", 80);
GUILayout.EndHorizontal();
if (GUILayout.Button("<b><color=cyan>Search</color></b>", null))
if (GUILayout.Button("<b><color=cyan>Search</color></b>", new GUILayoutOption[0]))
{
Search();
}
@ -254,15 +260,23 @@ namespace Explorer
private List<object> FindAllObjectsOfType(string searchQuery, string typeName)
{
#if CPP
Il2CppSystem.Type searchType = null;
#else
Type searchType = null;
#endif
if (TypeMode == TypeFilter.Custom)
{
try
{
if (ReflectionHelpers.GetTypeByName(typeName) is Type t)
{
#if CPP
searchType = Il2CppSystem.Type.GetType(t.AssemblyQualifiedName);
#else
searchType = t;
#endif
}
else
{
@ -271,7 +285,7 @@ namespace Explorer
}
catch (Exception e)
{
MelonLogger.Log("Exception getting Search Type: " + e.GetType() + ", " + e.Message);
ExplorerCore.Log("Exception getting Search Type: " + e.GetType() + ", " + e.Message);
}
}
else if (TypeMode == TypeFilter.Object)
@ -291,7 +305,7 @@ namespace Explorer
{
if (searchType != null)
{
MelonLogger.LogWarning("Your Custom Class Type must inherit from UnityEngine.Object!");
ExplorerCore.LogWarning("Your Custom Class Type must inherit from UnityEngine.Object!");
}
return new List<object>();
}
@ -300,7 +314,7 @@ namespace Explorer
var allObjectsOfType = Resources.FindObjectsOfTypeAll(searchType);
//MelonLogger.Log("Found count: " + allObjectsOfType.Length);
//ExplorerCore.Log("Found count: " + allObjectsOfType.Length);
int i = 0;
foreach (var obj in allObjectsOfType)
@ -313,7 +327,11 @@ namespace Explorer
}
if (searchType.FullName == ReflectionHelpers.ComponentType.FullName
#if CPP
&& ReflectionHelpers.TransformType.IsAssignableFrom(obj.GetIl2CppType()))
#else
&& ReflectionHelpers.TransformType.IsAssignableFrom(obj.GetType()))
#endif
{
// Transforms shouldn't really be counted as Components, skip them.
// They're more akin to GameObjects.
@ -338,15 +356,18 @@ namespace Explorer
public static bool FilterScene(object obj, SceneFilter filter)
{
GameObject go;
GameObject go = null;
#if CPP
if (obj is Il2CppSystem.Object ilObject)
{
go = ilObject.TryCast<GameObject>() ?? ilObject.TryCast<Component>().gameObject;
}
else
#else
if (obj is GameObject || obj is Component)
{
go = (obj as GameObject) ?? (obj as Component).gameObject;
}
#endif
if (!go)
{
@ -404,7 +425,7 @@ namespace Explorer
if (pi != null)
{
obj = pi.GetValue(null);
obj = pi.GetValue(null, null);
}
else
{