- Added ability to cycle through "pages" with lists/arrays and with search results. Also reduced default array display limit to 20 elements, since we can now just cycle through pages.
- Some backend restructuring / cleanups
This commit is contained in:
sinaioutlander
2020-08-13 00:06:39 +10:00
parent 13c2d6b92d
commit a2677e2321
30 changed files with 944 additions and 724 deletions

View File

@ -119,18 +119,5 @@ namespace Explorer
GUILayout.Space(10);
GUI.color = Color.white;
}
public abstract class WindowPage
{
public virtual string Name { get; set; }
public Vector2 scroll = Vector2.zero;
public abstract void Init();
public abstract void DrawWindow();
public abstract void Update();
}
}
}

View File

@ -12,9 +12,9 @@ using MelonLoader;
namespace Explorer
{
public class ConsolePage : MainMenu.WindowPage
public class ConsolePage : WindowPage
{
public override string Name { get => "Console"; set => base.Name = value; }
public override string Name { get => "C# Console"; set => base.Name = value; }
private ScriptEvaluator _evaluator;
private readonly StringBuilder _sb = new StringBuilder();
@ -41,13 +41,18 @@ namespace Explorer
try
{
MethodInput = @"// This is a basic REPL console used to execute a method.
// Some common directives are added by default, you can add more below.
MethodInput = @"// This is a basic C# REPL console.
// Some common using directives are added by default, you can add more below.
// If you want to return some output, MelonLogger.Log() it.
MelonLogger.Log(""hello world"");";
ResetConsole();
foreach (var use in m_defaultUsing)
{
AddUsing(use);
}
}
catch (Exception e)
{
@ -65,11 +70,6 @@ MelonLogger.Log(""hello world"");";
_evaluator = new ScriptEvaluator(new StringWriter(_sb)) { InteractiveBaseClass = typeof(REPL) };
UsingDirectives = new List<string>();
UsingDirectives.AddRange(m_defaultUsing);
foreach (string asm in UsingDirectives)
{
Evaluate(AsmToUsing(asm));
}
}
public string AsmToUsing(string asm, bool richtext = false)
@ -111,7 +111,7 @@ MelonLogger.Log(""hello world"");";
public override void DrawWindow()
{
GUILayout.Label("<b><size=15><color=cyan>REPL Console</color></size></b>", null);
GUILayout.Label("<b><size=15><color=cyan>C# REPL Console</color></size></b>", null);
GUILayout.Label("Method:", null);
MethodInput = GUILayout.TextArea(MethodInput, new GUILayoutOption[] { GUILayout.Height(300) });

View File

@ -8,7 +8,7 @@ using UnityEngine.SceneManagement;
namespace Explorer
{
public class ScenePage : MainMenu.WindowPage
public class ScenePage : WindowPage
{
public static ScenePage Instance;
@ -45,7 +45,7 @@ namespace Explorer
public override void Update()
{
if (Time.time - m_timeOfLastUpdate < 1f)
if (Time.time - m_timeOfLastUpdate < 0.2f)
{
return;
}

View File

@ -12,15 +12,16 @@ using UnhollowerBaseLib;
namespace Explorer
{
public class SearchPage : MainMenu.WindowPage
public class SearchPage : WindowPage
{
public static SearchPage Instance;
public override string Name { get => "Advanced Search"; set => base.Name = value; }
public override string Name { get => "Object Search"; set => base.Name = value; }
private string m_searchInput = "";
private string m_typeInput = "";
private int m_limit = 100;
private int m_pageOffset = 0;
public SceneFilter SceneMode = SceneFilter.Any;
public TypeFilter TypeMode = TypeFilter.Object;
@ -52,6 +53,7 @@ namespace Explorer
public void OnSceneChange()
{
m_searchResults.Clear();
m_pageOffset = 0;
}
public override void Update()
@ -68,6 +70,7 @@ namespace Explorer
if (GUILayout.Button("Find Static Instances", new GUILayoutOption[] { GUILayout.Width(180) }))
{
m_searchResults = GetInstanceClassScanner().ToList();
m_pageOffset = 0;
}
GUILayout.EndHorizontal();
@ -78,21 +81,59 @@ namespace Explorer
GUILayout.BeginVertical(GUI.skin.box, null);
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label("<b><color=orange>Results</color></b>", null);
GUILayout.Label("<b><color=orange>Results </color></b>" + " (" + m_searchResults.Count + ")", null);
GUI.skin.label.alignment = TextAnchor.UpperLeft;
int count = m_searchResults.Count;
if (count > CppExplorer.ArrayLimit)
{
// prev/next page buttons
GUILayout.BeginHorizontal(null);
int maxOffset = (int)Mathf.Ceil(count / CppExplorer.ArrayLimit);
if (GUILayout.Button("< Prev", null))
{
if (m_pageOffset > 0) m_pageOffset--;
}
GUILayout.Label($"Page {m_pageOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
if (GUILayout.Button("Next >", null))
{
if (m_pageOffset < maxOffset) m_pageOffset++;
}
GUILayout.EndHorizontal();
}
resultsScroll = GUILayout.BeginScrollView(resultsScroll, GUI.skin.scrollView);
var _temprect = new Rect(MainMenu.MainRect.x, MainMenu.MainRect.y, MainMenu.MainRect.width + 160, MainMenu.MainRect.height);
if (m_searchResults.Count > 0)
{
int offset = m_pageOffset * CppExplorer.ArrayLimit;
int preiterated = 0;
if (offset >= count) offset = 0;
for (int i = 0; i < m_searchResults.Count; i++)
{
if (offset > 0 && preiterated < offset)
{
preiterated++;
continue;
}
if (i - offset > CppExplorer.ArrayLimit - 1)
{
break;
}
var obj = m_searchResults[i];
bool _ = false;
UIStyles.DrawValue(ref obj, _temprect, ref _);
int __ = 0;
UIStyles.DrawValue(ref obj, ref _, ref __, _temprect);
}
}
else
@ -125,7 +166,7 @@ namespace Explorer
m_searchInput = GUILayout.TextField(m_searchInput, new GUILayoutOption[] { GUILayout.Width(200) });
GUI.skin.label.alignment = TextAnchor.MiddleRight;
GUILayout.Label("Result limit:", new GUILayoutOption[] { GUILayout.Width(100) });
GUILayout.Label("Results per page:", new GUILayoutOption[] { GUILayout.Width(120) });
var resultinput = m_limit.ToString();
resultinput = GUILayout.TextField(resultinput, new GUILayoutOption[] { GUILayout.Width(55) });
if (int.TryParse(resultinput, out int _i) && _i > 0)
@ -289,26 +330,9 @@ namespace Explorer
}
var matches = new List<object>();
int added = 0;
//MelonLogger.Log("Trying to get IL Type. ASM name: " + type.Assembly.GetName().Name + ", Namespace: " + type.Namespace + ", name: " + type.Name);
//var asmName = type.Assembly.GetName().Name;
//if (asmName.Contains("UnityEngine"))
//{
// asmName = "UnityEngine";
//}
//var intPtr = IL2CPP.GetIl2CppClass(asmName, type.Namespace, type.Name);
//var ilType = Il2CppType.TypeFromPointer(intPtr);
foreach (var obj in Resources.FindObjectsOfTypeAll(type))
{
if (added == m_limit)
{
break;
}
if (_search != "" && !obj.name.ToLower().Contains(_search.ToLower()))
{
continue;
@ -360,7 +384,6 @@ namespace Explorer
if (!matches.Contains(obj))
{
matches.Add(obj);
added++;
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Explorer
{
public abstract class WindowPage
{
public virtual string Name { get; set; }
public Vector2 scroll = Vector2.zero;
public abstract void Init();
public abstract void DrawWindow();
public abstract void Update();
}
}