mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-27 18:42:46 +08:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
fd20a1120b | |||
abcb548706 | |||
b056644385 | |||
71f72e8f36 | |||
1ab41f5a30 | |||
7dc58ea02c | |||
68eeee353e | |||
92fe1dc704 | |||
6e644b4f50 | |||
c47974115b | |||
535e88be9a | |||
e567c16221 | |||
d13af7548e | |||
5d750aec77 |
67
README.md
67
README.md
@ -14,8 +14,10 @@
|
|||||||
<img src="https://img.shields.io/github/downloads/sinai-dev/CppExplorer/total.svg" />
|
<img src="https://img.shields.io/github/downloads/sinai-dev/CppExplorer/total.svg" />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
### Note
|
### Known issue
|
||||||
Most games running on Unity 2017 to 2019 should be supported. If you find that the GUI does not display properly and you get errors in the MelonLoader console about it, then this is likely due to a bug with Il2CppAssemblyUnhollower's unstripping. This bug is known by the developer of the tool and they will fix it as soon as they are able to.
|
Some games are experiencing `MissingMethodException`s or exceptions about failed unstripping, which prevent the CppExplorer menu from showing properly or at all. This is a bug with [Il2CppAssemblyUnhollower](https://github.com/knah/Il2CppAssemblyUnhollower) and there isn't much I can do about it myself.
|
||||||
|
|
||||||
|
If you're familiar with C# and Unity, one possibility for now is making a fork of this repo and manually fixing all the broken methods to ones which aren't broken (if possible). There may be another overload of the same method which wasn't stripped or was unstripped successfully, which you can use instead.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
* Scene hierarchy explorer
|
* Scene hierarchy explorer
|
||||||
@ -36,34 +38,63 @@ Requires [MelonLoader](https://github.com/HerpDerpinstine/MelonLoader) to be ins
|
|||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
* Press F7 to show or hide the menu.
|
* Press F7 to show or hide the menu.
|
||||||
* Simply browse through the scene, search for objects, etc, it's pretty self-explanatory.
|
* Simply browse through the scene, search for objects, etc, most of it is pretty self-explanatory.
|
||||||
|
|
||||||
### Help! I can't use the mouse!
|
### Scene Explorer
|
||||||
|
|
||||||
It is fairly common for games to override mouse control with their own mouse behaviour. Unfortunately, it's not feasible for CppExplorer to handle this due to how differently every game will go about it.
|
* A simple menu which allows you to traverse the Transform heirarchy of the scene.
|
||||||
|
* Click on a GameObject to set it as the current path, or <b>Inspect</b> it to send it to an Inspector Window.
|
||||||
|
|
||||||
In order to fix this problem, you can:
|
[](https://i.imgur.com/2b0q0jL.png)
|
||||||
* Use [VRCExplorerMouseControl](https://github.com/sinaioutlander/VRCExplorerMouseControl) (for VRChat)
|
|
||||||
* Use [HPExplorerMouseControl](https://github.com/sinaioutlander/Hellpoint-Mods/tree/master/HPExplorerMouseControl/HPExplorerMouseControl) (for Hellpoint)
|
|
||||||
* In general, pressing Escape (to open a menu) will usually give you temporary control over the mouse.
|
|
||||||
* Create your own mini-plugin using one of the two plugins above as an example. Usually only 1 or 2 simple Harmony patches are needed to fix the problem.
|
|
||||||
|
|
||||||
## Images
|
### Inspectors
|
||||||
|
|
||||||
<i>Note: images may be slightly outdated, taken from version 1.2</i>.
|
CppExplorer has two main inspector modes: <b>GameObject Inspector</b>, and <b>Reflection Inspector</b>.
|
||||||
|
|
||||||
Scene explorer, and inspection of a MonoBehaviour object:
|
<b>Tip:</b> when in Tab View, GameObjects are denoted by a [G] prefix, and Reflection objects are denoted by a [R] prefix.
|
||||||
|
|
||||||
[](https://i.imgur.com/Yxizwcz.png)
|
### GameObject Inspector
|
||||||
|
|
||||||
Search feature:
|
* Allows you to see the children and components on a GameObject.
|
||||||
|
* Can use some basic GameObject Controls such as translating and rotating the object, destroy it, clone it, etc.
|
||||||
|
|
||||||
[](https://i.imgur.com/F9ZfMvz.png)
|
[](https://i.imgur.com/JTxqlx4.png)
|
||||||
|
|
||||||
|
### Reflection Inspector
|
||||||
|
|
||||||
C# REPL console:
|
* The Reflection Inspector is used for all other supported objects.
|
||||||
|
* Allows you to inspect Properties, Fields and basic Methods, as well as set primitive values and evaluate primitive methods.
|
||||||
|
* Can search and filter members for the ones you are interested in.
|
||||||
|
|
||||||
[](https://i.imgur.com/14Dbtf8.png)
|
[](https://i.imgur.com/eFVTQdh.png)
|
||||||
|
|
||||||
|
### Object Search
|
||||||
|
|
||||||
|
* You can search for an `UnityEngine.Object` with the Object Search feature.
|
||||||
|
* Filter by name, type, etc.
|
||||||
|
* For GameObjects and Transforms you can filter which scene they are found in too.
|
||||||
|
|
||||||
|
[](https://i.imgur.com/lK2RthM.png)
|
||||||
|
|
||||||
|
### C# REPL console
|
||||||
|
|
||||||
|
* A simple C# REPL console, allows you to execute a method body on the fly.
|
||||||
|
|
||||||
|
[](https://i.imgur.com/5U4D1a8.png)
|
||||||
|
|
||||||
|
### Inspect-under-mouse
|
||||||
|
|
||||||
|
* Press Shift+RMB (Right Mouse Button) while the CppExplorer menu is open to begin Inspect-Under-Mouse.
|
||||||
|
* Hover over your desired object, if you see the name appear then you can click on it to inspect it.
|
||||||
|
* Only objects with Colliders are supported.
|
||||||
|
|
||||||
|
### Mouse Control
|
||||||
|
|
||||||
|
CppExplorer can force the mouse to be visible and unlocked when the menu is open, if you have enabled "Force Unlock Mouse" (Left-Alt toggle). However, you may also want to prevent the mouse clicking-through onto the game behind CppExplorer, this is possible but it requires specific patches for that game.
|
||||||
|
|
||||||
|
* For VRChat, use [VRCExplorerMouseControl](https://github.com/sinai-dev/VRCExplorerMouseControl)
|
||||||
|
* For Hellpoint, use [HPExplorerMouseControl](https://github.com/sinai-dev/Hellpoint-Mods/tree/master/HPExplorerMouseControl/HPExplorerMouseControl)
|
||||||
|
* You can create your own plugin using one of the two plugins above as an example. Usually only a few simple Harmony patches are needed to fix the problem.
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
|
34
src/CachedObjects/CacheDictionary.cs
Normal file
34
src/CachedObjects/CacheDictionary.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MelonLoader;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Explorer
|
||||||
|
{
|
||||||
|
public class CacheDictionary : CacheObjectBase
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
//base.Init();
|
||||||
|
|
||||||
|
Value = "Unsupported";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateValue()
|
||||||
|
{
|
||||||
|
//base.UpdateValue();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawValue(Rect window, float width)
|
||||||
|
{
|
||||||
|
GUILayout.Label("<color=red>Dictionary (unsupported)</color>", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace Explorer
|
namespace Explorer
|
||||||
{
|
{
|
||||||
public class CacheEnum : CacheObject
|
public class CacheEnum : CacheObjectBase
|
||||||
{
|
{
|
||||||
public Type EnumType;
|
public Type EnumType;
|
||||||
public string[] EnumNames;
|
public string[] EnumNames;
|
||||||
|
@ -8,7 +8,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace Explorer
|
namespace Explorer
|
||||||
{
|
{
|
||||||
public class CacheGameObject : CacheObject
|
public class CacheGameObject : CacheObjectBase
|
||||||
{
|
{
|
||||||
private GameObject GameObj
|
private GameObject GameObj
|
||||||
{
|
{
|
||||||
|
@ -3,26 +3,41 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Mono.CSharp;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Explorer
|
namespace Explorer
|
||||||
{
|
{
|
||||||
public partial class CacheList : CacheObject
|
public partial class CacheList : CacheObjectBase
|
||||||
{
|
{
|
||||||
public bool IsExpanded { get; set; }
|
public bool IsExpanded { get; set; }
|
||||||
public int ArrayOffset { get; set; }
|
public int ArrayOffset { get; set; }
|
||||||
public int ArrayLimit { get; set; } = 20;
|
public int ArrayLimit { get; set; } = 20;
|
||||||
|
|
||||||
|
public float WhiteSpace = 215f;
|
||||||
|
public float ButtonWidthOffset = 290f;
|
||||||
|
|
||||||
public Type EntryType
|
public Type EntryType
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (m_entryType == null)
|
if (m_entryType == null)
|
||||||
{
|
{
|
||||||
m_entryType = Value?.GetType().GetGenericArguments()[0];
|
if (this.MemberInfo != null)
|
||||||
|
{
|
||||||
|
switch (this.MemberInfo.MemberType)
|
||||||
|
{
|
||||||
|
case MemberTypes.Field:
|
||||||
|
m_entryType = (MemberInfo as FieldInfo).FieldType.GetGenericArguments()[0];
|
||||||
|
break;
|
||||||
|
case MemberTypes.Property:
|
||||||
|
m_entryType = (MemberInfo as PropertyInfo).PropertyType.GetGenericArguments()[0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Value != null)
|
||||||
|
{
|
||||||
|
m_entryType = Value.GetType().GetGenericArguments()[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return m_entryType;
|
return m_entryType;
|
||||||
}
|
}
|
||||||
@ -39,23 +54,32 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
if (m_enumerable == null && Value != null)
|
if (m_enumerable == null && Value != null)
|
||||||
{
|
{
|
||||||
m_enumerable = Value as IEnumerable ?? CppListToEnumerable(Value);
|
m_enumerable = Value as IEnumerable ?? CastValueFromList();
|
||||||
}
|
}
|
||||||
return m_enumerable;
|
return m_enumerable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable m_enumerable;
|
private IEnumerable m_enumerable;
|
||||||
private CacheObject[] m_cachedEntries;
|
private CacheObjectBase[] m_cachedEntries;
|
||||||
|
|
||||||
private IEnumerable CppListToEnumerable(object list)
|
public MethodInfo GenericToArrayMethod
|
||||||
|
{
|
||||||
|
get
|
||||||
{
|
{
|
||||||
if (EntryType == null) return null;
|
if (EntryType == null) return null;
|
||||||
|
|
||||||
return (IEnumerable)typeof(Il2CppSystem.Collections.Generic.List<>)
|
return m_genericToArray ??
|
||||||
.MakeGenericType(new Type[] { EntryType })
|
(m_genericToArray = typeof(Il2CppSystem.Collections.Generic.List<>)
|
||||||
.GetMethod("ToArray")
|
.MakeGenericType(new Type[] { this.EntryType })
|
||||||
.Invoke(list, new object[0]);
|
.GetMethod("ToArray"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private MethodInfo m_genericToArray;
|
||||||
|
|
||||||
|
private IEnumerable CastValueFromList()
|
||||||
|
{
|
||||||
|
return (Value == null) ? null : (IEnumerable)GenericToArrayMethod?.Invoke(Value, new object[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawValue(Rect window, float width)
|
public override void DrawValue(Rect window, float width)
|
||||||
@ -79,27 +103,38 @@ namespace Explorer
|
|||||||
|
|
||||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||||
string btnLabel = "<color=yellow>[" + count + "] " + EntryType + "</color>";
|
string btnLabel = "<color=yellow>[" + count + "] " + EntryType + "</color>";
|
||||||
if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.MaxWidth(window.width - 260) }))
|
if (GUILayout.Button(btnLabel, new GUILayoutOption[] { GUILayout.MaxWidth(window.width - ButtonWidthOffset) }))
|
||||||
{
|
{
|
||||||
WindowManager.InspectObject(Value, out bool _);
|
WindowManager.InspectObject(Value, out bool _);
|
||||||
}
|
}
|
||||||
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
||||||
|
|
||||||
|
GUILayout.Space(5);
|
||||||
|
|
||||||
if (IsExpanded)
|
if (IsExpanded)
|
||||||
{
|
{
|
||||||
|
float whitespace = WhiteSpace;
|
||||||
|
|
||||||
|
if (whitespace > 0)
|
||||||
|
{
|
||||||
|
ClampLabelWidth(window, ref whitespace);
|
||||||
|
}
|
||||||
|
|
||||||
if (count > ArrayLimit)
|
if (count > ArrayLimit)
|
||||||
{
|
{
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
GUILayout.Space(190);
|
|
||||||
|
GUILayout.Space(whitespace);
|
||||||
|
|
||||||
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)ArrayLimit)) - 1;
|
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)ArrayLimit)) - 1;
|
||||||
GUILayout.Label($"Page {ArrayOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
|
GUILayout.Label($"Page {ArrayOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
|
||||||
// prev/next page buttons
|
// prev/next page buttons
|
||||||
if (GUILayout.Button("< Prev", null))
|
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(60) }))
|
||||||
{
|
{
|
||||||
if (ArrayOffset > 0) ArrayOffset--;
|
if (ArrayOffset > 0) ArrayOffset--;
|
||||||
}
|
}
|
||||||
if (GUILayout.Button("Next >", null))
|
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(60) }))
|
||||||
{
|
{
|
||||||
if (ArrayOffset < maxOffset) ArrayOffset++;
|
if (ArrayOffset < maxOffset) ArrayOffset++;
|
||||||
}
|
}
|
||||||
@ -110,11 +145,17 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
ArrayLimit = i;
|
ArrayLimit = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUILayout.Space(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
int offset = ArrayOffset * ArrayLimit;
|
int offset = ArrayOffset * ArrayLimit;
|
||||||
|
|
||||||
if (offset >= count) offset = 0;
|
if (offset >= count)
|
||||||
|
{
|
||||||
|
offset = 0;
|
||||||
|
ArrayOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = offset; i < offset + ArrayLimit && i < count; i++)
|
for (int i = offset; i < offset + ArrayLimit && i < count; i++)
|
||||||
{
|
{
|
||||||
@ -123,24 +164,27 @@ namespace Explorer
|
|||||||
//collapsing the BeginHorizontal called from ReflectionWindow.WindowFunction or previous array entry
|
//collapsing the BeginHorizontal called from ReflectionWindow.WindowFunction or previous array entry
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
GUILayout.Space(190);
|
|
||||||
|
GUILayout.Space(whitespace);
|
||||||
|
|
||||||
if (entry.Value == null)
|
if (entry.Value == null)
|
||||||
{
|
{
|
||||||
GUILayout.Label("<i><color=grey>null</color></i>", null);
|
GUILayout.Label(i + "<i><color=grey> (null)</color></i>", null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GUILayout.Label(i.ToString(), new GUILayoutOption[] { GUILayout.Width(30) });
|
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||||
|
GUILayout.Label($"[{i}]", new GUILayoutOption[] { GUILayout.Width(30) });
|
||||||
|
entry.DrawValue(window, window.width - (whitespace + 85));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entry.DrawValue(window, window.width - 250);
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the user presses the "Update" button, or if AutoUpdate is on.
|
/// Called only when the user presses the "Update" button, or if AutoUpdate is on.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override void UpdateValue()
|
public override void UpdateValue()
|
||||||
{
|
{
|
||||||
@ -152,7 +196,7 @@ namespace Explorer
|
|||||||
|
|
||||||
if (enumerator == null) return;
|
if (enumerator == null) return;
|
||||||
|
|
||||||
var list = new List<CacheObject>();
|
var list = new List<CacheObjectBase>();
|
||||||
while (enumerator.MoveNext())
|
while (enumerator.MoveNext())
|
||||||
{
|
{
|
||||||
list.Add(GetCacheObject(enumerator.Current, null, null, this.EntryType));
|
list.Add(GetCacheObject(enumerator.Current, null, null, this.EntryType));
|
||||||
|
223
src/CachedObjects/CacheMethod.cs
Normal file
223
src/CachedObjects/CacheMethod.cs
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
using MelonLoader;
|
||||||
|
|
||||||
|
namespace Explorer
|
||||||
|
{
|
||||||
|
public class CacheMethod : CacheObjectBase
|
||||||
|
{
|
||||||
|
private bool m_evaluated = false;
|
||||||
|
private CacheObjectBase m_cachedReturnValue;
|
||||||
|
|
||||||
|
private bool m_isEvaluating;
|
||||||
|
private ParameterInfo[] m_arguments;
|
||||||
|
private string[] m_argumentInput;
|
||||||
|
|
||||||
|
public bool HasParameters
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (m_hasParams == null)
|
||||||
|
{
|
||||||
|
m_hasParams = (MemberInfo as MethodInfo).GetParameters().Length > 0;
|
||||||
|
}
|
||||||
|
return (bool)m_hasParams;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private bool? m_hasParams;
|
||||||
|
|
||||||
|
public static bool CanEvaluate(MethodInfo mi)
|
||||||
|
{
|
||||||
|
// generic type args not supported yet
|
||||||
|
if (mi.GetGenericArguments().Length > 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only primitive and string args supported
|
||||||
|
foreach (var param in mi.GetParameters())
|
||||||
|
{
|
||||||
|
if (!param.ParameterType.IsPrimitive && param.ParameterType != typeof(string))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Init()
|
||||||
|
{
|
||||||
|
base.Init();
|
||||||
|
|
||||||
|
var mi = MemberInfo as MethodInfo;
|
||||||
|
|
||||||
|
m_arguments = mi.GetParameters();
|
||||||
|
m_argumentInput = new string[m_arguments.Length];
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void UpdateValue()
|
||||||
|
{
|
||||||
|
base.UpdateValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawValue(Rect window, float width)
|
||||||
|
{
|
||||||
|
GUILayout.BeginVertical(null);
|
||||||
|
|
||||||
|
string evaluateLabel = "<color=lime>Evaluate</color>";
|
||||||
|
if (HasParameters)
|
||||||
|
{
|
||||||
|
if (m_isEvaluating)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < m_arguments.Length; i++)
|
||||||
|
{
|
||||||
|
var name = m_arguments[i].Name;
|
||||||
|
var input = m_argumentInput[i];
|
||||||
|
var type = m_arguments[i].ParameterType.Name;
|
||||||
|
|
||||||
|
GUILayout.BeginHorizontal(null);
|
||||||
|
m_argumentInput[i] = GUILayout.TextField(input, new GUILayoutOption[] { GUILayout.Width(150) });
|
||||||
|
GUILayout.Label(i + ": <color=cyan>" + name + "</color> <color=yellow>(" + type + ")</color>", null);
|
||||||
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.BeginHorizontal(null);
|
||||||
|
if (GUILayout.Button(evaluateLabel, new GUILayoutOption[] { GUILayout.Width(70) }))
|
||||||
|
{
|
||||||
|
Evaluate();
|
||||||
|
m_isEvaluating = false;
|
||||||
|
}
|
||||||
|
if (GUILayout.Button("Cancel", new GUILayoutOption[] { GUILayout.Width(70) }))
|
||||||
|
{
|
||||||
|
m_isEvaluating = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUILayout.BeginHorizontal(null);
|
||||||
|
if (GUILayout.Button($"Evaluate ({m_arguments.Length} params)", new GUILayoutOption[] { GUILayout.Width(150) }))
|
||||||
|
{
|
||||||
|
m_isEvaluating = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUILayout.BeginHorizontal(null);
|
||||||
|
if (GUILayout.Button(evaluateLabel, new GUILayoutOption[] { GUILayout.Width(70) }))
|
||||||
|
{
|
||||||
|
Evaluate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
GUILayout.BeginHorizontal(null);
|
||||||
|
if (m_evaluated)
|
||||||
|
{
|
||||||
|
if (m_cachedReturnValue != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_cachedReturnValue.DrawValue(window, width);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
MelonLogger.Log("Exception drawing m_cachedReturnValue!");
|
||||||
|
MelonLogger.Log(e.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUILayout.Label($"null (<color=yellow>{ValueType}</color>)", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUILayout.Label($"<color=grey><i>Not yet evaluated</i></color> (<color=yellow>{ValueType}</color>)", null);
|
||||||
|
}
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
GUILayout.EndVertical();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Evaluate()
|
||||||
|
{
|
||||||
|
var mi = MemberInfo as MethodInfo;
|
||||||
|
|
||||||
|
object ret = null;
|
||||||
|
|
||||||
|
if (!HasParameters)
|
||||||
|
{
|
||||||
|
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, new object[0]);
|
||||||
|
m_evaluated = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var arguments = new List<object>();
|
||||||
|
for (int i = 0; i < m_arguments.Length; i++)
|
||||||
|
{
|
||||||
|
var input = m_argumentInput[i];
|
||||||
|
var type = m_arguments[i].ParameterType;
|
||||||
|
|
||||||
|
if (type == typeof(string))
|
||||||
|
{
|
||||||
|
arguments.Add(input);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (type.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { input }) is object parsed)
|
||||||
|
{
|
||||||
|
arguments.Add(parsed);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
MelonLogger.Log($"Unable to parse '{input}' to type '{type.Name}'");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.Count == m_arguments.Length)
|
||||||
|
{
|
||||||
|
ret = mi.Invoke(mi.IsStatic ? null : DeclaringInstance, arguments.ToArray());
|
||||||
|
m_evaluated = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MelonLogger.Log($"Did not invoke because {m_arguments.Length - arguments.Count} arguments could not be parsed!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != null)
|
||||||
|
{
|
||||||
|
m_cachedReturnValue = GetCacheObject(ret);
|
||||||
|
if (m_cachedReturnValue is CacheList cacheList)
|
||||||
|
{
|
||||||
|
cacheList.WhiteSpace = 0f;
|
||||||
|
cacheList.ButtonWidthOffset += 70f;
|
||||||
|
}
|
||||||
|
m_cachedReturnValue.UpdateValue();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_cachedReturnValue = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,14 +10,13 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace Explorer
|
namespace Explorer
|
||||||
{
|
{
|
||||||
public abstract class CacheObject
|
public abstract class CacheObjectBase
|
||||||
{
|
{
|
||||||
public object Value;
|
public object Value;
|
||||||
public string ValueType;
|
public string ValueType;
|
||||||
|
|
||||||
// Reflection window only
|
// Reflection window only
|
||||||
public MemberInfo MemberInfo { get; set; }
|
public MemberInfo MemberInfo { get; set; }
|
||||||
// public ReflectionWindow.MemberInfoType MemberInfoType { get; set; }
|
|
||||||
public Type DeclaringType { get; set; }
|
public Type DeclaringType { get; set; }
|
||||||
public object DeclaringInstance { get; set; }
|
public object DeclaringInstance { get; set; }
|
||||||
public string FullName => $"{MemberInfo.DeclaringType.Name}.{MemberInfo.Name}";
|
public string FullName => $"{MemberInfo.DeclaringType.Name}.{MemberInfo.Name}";
|
||||||
@ -42,22 +41,11 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReflectionWindow.MemberInfoType MemberInfoType
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (MemberInfo is FieldInfo) return ReflectionWindow.MemberInfoType.Field;
|
|
||||||
if (MemberInfo is PropertyInfo) return ReflectionWindow.MemberInfoType.Property;
|
|
||||||
if (MemberInfo is MethodInfo) return ReflectionWindow.MemberInfoType.Method;
|
|
||||||
return ReflectionWindow.MemberInfoType.All;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public virtual void Init() { }
|
public virtual void Init() { }
|
||||||
public abstract void DrawValue(Rect window, float width);
|
public abstract void DrawValue(Rect window, float width);
|
||||||
|
|
||||||
public static CacheObject GetCacheObject(object obj)
|
public static CacheObjectBase GetCacheObject(object obj)
|
||||||
{
|
{
|
||||||
return GetCacheObject(obj, null, null);
|
return GetCacheObject(obj, null, null);
|
||||||
}
|
}
|
||||||
@ -69,13 +57,39 @@ namespace Explorer
|
|||||||
/// <param name="memberInfo">The MemberInfo (can be null if obj is not null)</param>
|
/// <param name="memberInfo">The MemberInfo (can be null if obj is not null)</param>
|
||||||
/// <param name="declaringInstance">If MemberInfo is not null, the declaring class instance. Can be null if static.</param>
|
/// <param name="declaringInstance">If MemberInfo is not null, the declaring class instance. Can be null if static.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static CacheObject GetCacheObject(object obj, MemberInfo memberInfo, object declaringInstance)
|
public static CacheObjectBase GetCacheObject(object obj, MemberInfo memberInfo, object declaringInstance)
|
||||||
{
|
{
|
||||||
var type = ReflectionHelpers.GetActualType(obj) ?? (memberInfo as FieldInfo)?.FieldType ?? (memberInfo as PropertyInfo)?.PropertyType;
|
//var type = ReflectionHelpers.GetActualType(obj) ?? (memberInfo as FieldInfo)?.FieldType ?? (memberInfo as PropertyInfo)?.PropertyType;
|
||||||
|
|
||||||
|
Type type = null;
|
||||||
|
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
type = ReflectionHelpers.GetActualType(obj);
|
||||||
|
}
|
||||||
|
else if (memberInfo != null)
|
||||||
|
{
|
||||||
|
if (memberInfo is FieldInfo fi)
|
||||||
|
{
|
||||||
|
type = fi.FieldType;
|
||||||
|
}
|
||||||
|
else if (memberInfo is PropertyInfo pi)
|
||||||
|
{
|
||||||
|
type = pi.PropertyType;
|
||||||
|
}
|
||||||
|
else if (memberInfo is MethodInfo mi)
|
||||||
|
{
|
||||||
|
type = mi.ReturnType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (type == null)
|
if (type == null)
|
||||||
{
|
{
|
||||||
MelonLogger.Log("Could not get type for object or memberinfo!");
|
MelonLogger.Log("Could not get type for object or memberinfo!");
|
||||||
|
if (memberInfo is MethodInfo)
|
||||||
|
{
|
||||||
|
MelonLogger.Log("is it void?");
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,52 +102,82 @@ namespace Explorer
|
|||||||
/// <param name="obj">The current value (can be null if memberInfo is not null)</param>
|
/// <param name="obj">The current value (can be null if memberInfo is not null)</param>
|
||||||
/// <param name="memberInfo">The MemberInfo (can be null if obj is not null)</param>
|
/// <param name="memberInfo">The MemberInfo (can be null if obj is not null)</param>
|
||||||
/// <param name="declaringInstance">If MemberInfo is not null, the declaring class instance. Can be null if static.</param>
|
/// <param name="declaringInstance">If MemberInfo is not null, the declaring class instance. Can be null if static.</param>
|
||||||
/// <param name="type">The type of the object or MemberInfo value.</param>
|
/// <param name="valueType">The type of the object or MemberInfo value.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static CacheObject GetCacheObject(object obj, MemberInfo memberInfo, object declaringInstance, Type type)
|
public static CacheObjectBase GetCacheObject(object obj, MemberInfo memberInfo, object declaringInstance, Type valueType)
|
||||||
{
|
{
|
||||||
CacheObject holder;
|
CacheObjectBase holder;
|
||||||
|
|
||||||
if ((obj is Il2CppSystem.Object || typeof(Il2CppSystem.Object).IsAssignableFrom(type))
|
if (memberInfo is MethodInfo mi)
|
||||||
&& (type.FullName.Contains("UnityEngine.GameObject") || type.FullName.Contains("UnityEngine.Transform")))
|
{
|
||||||
|
if (CacheMethod.CanEvaluate(mi))
|
||||||
|
{
|
||||||
|
holder = new CacheMethod();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (valueType == typeof(GameObject) || valueType == typeof(Transform))
|
||||||
{
|
{
|
||||||
holder = new CacheGameObject();
|
holder = new CacheGameObject();
|
||||||
}
|
}
|
||||||
else if (type.IsPrimitive || type == typeof(string))
|
else if (valueType.IsPrimitive || valueType == typeof(string))
|
||||||
{
|
{
|
||||||
holder = new CachePrimitive();
|
holder = new CachePrimitive();
|
||||||
}
|
}
|
||||||
else if (type.IsEnum)
|
else if (valueType.IsEnum)
|
||||||
{
|
{
|
||||||
holder = new CacheEnum();
|
holder = new CacheEnum();
|
||||||
}
|
}
|
||||||
else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(type) || ReflectionHelpers.IsList(type))
|
else if (ReflectionHelpers.IsArray(valueType) || ReflectionHelpers.IsList(valueType))
|
||||||
{
|
{
|
||||||
holder = new CacheList();
|
holder = new CacheList();
|
||||||
}
|
}
|
||||||
|
else if (ReflectionHelpers.IsDictionary(valueType))
|
||||||
|
{
|
||||||
|
holder = new CacheDictionary();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
holder = new CacheOther();
|
holder = new CacheOther();
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.Value = obj;
|
holder.Value = obj;
|
||||||
holder.ValueType = type.FullName;
|
holder.ValueType = valueType.FullName;
|
||||||
|
|
||||||
if (memberInfo != null)
|
if (memberInfo != null)
|
||||||
{
|
{
|
||||||
holder.MemberInfo = memberInfo;
|
holder.MemberInfo = memberInfo;
|
||||||
holder.DeclaringType = memberInfo.DeclaringType;
|
holder.DeclaringType = memberInfo.DeclaringType;
|
||||||
holder.DeclaringInstance = declaringInstance;
|
holder.DeclaringInstance = declaringInstance;
|
||||||
}
|
|
||||||
|
|
||||||
holder.UpdateValue();
|
holder.UpdateValue();
|
||||||
|
}
|
||||||
|
|
||||||
holder.Init();
|
holder.Init();
|
||||||
|
|
||||||
return holder;
|
return holder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public const float MAX_LABEL_WIDTH = 400f;
|
||||||
|
|
||||||
|
public static void ClampLabelWidth(Rect window, ref float labelWidth)
|
||||||
|
{
|
||||||
|
float min = window.width * 0.37f;
|
||||||
|
if (min > MAX_LABEL_WIDTH) min = MAX_LABEL_WIDTH;
|
||||||
|
|
||||||
|
labelWidth = Mathf.Clamp(labelWidth, min, MAX_LABEL_WIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
public void Draw(Rect window, float labelWidth = 215f)
|
public void Draw(Rect window, float labelWidth = 215f)
|
||||||
{
|
{
|
||||||
|
if (labelWidth > 0)
|
||||||
|
{
|
||||||
|
ClampLabelWidth(window, ref labelWidth);
|
||||||
|
}
|
||||||
|
|
||||||
if (MemberInfo != null)
|
if (MemberInfo != null)
|
||||||
{
|
{
|
||||||
GUILayout.Label("<color=cyan>" + FullName + "</color>", new GUILayoutOption[] { GUILayout.Width(labelWidth) });
|
GUILayout.Label("<color=cyan>" + FullName + "</color>", new GUILayoutOption[] { GUILayout.Width(labelWidth) });
|
||||||
@ -147,7 +191,7 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
GUILayout.Label("<color=red>Reflection failed!</color> (" + ReflectionException + ")", null);
|
GUILayout.Label("<color=red>Reflection failed!</color> (" + ReflectionException + ")", null);
|
||||||
}
|
}
|
||||||
else if (Value == null)
|
else if (Value == null && MemberInfo?.MemberType != MemberTypes.Method)
|
||||||
{
|
{
|
||||||
GUILayout.Label("<i>null (" + ValueType + ")</i>", null);
|
GUILayout.Label("<i>null (" + ValueType + ")</i>", null);
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace Explorer
|
namespace Explorer
|
||||||
{
|
{
|
||||||
public class CacheOther : CacheObject
|
public class CacheOther : CacheObjectBase
|
||||||
{
|
{
|
||||||
private MethodInfo m_toStringMethod;
|
private MethodInfo m_toStringMethod;
|
||||||
private bool m_triedToGetMethod;
|
private bool m_triedToGetMethod;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Explorer
|
namespace Explorer
|
||||||
{
|
{
|
||||||
public class CachePrimitive : CacheObject
|
public class CachePrimitive : CacheObjectBase
|
||||||
{
|
{
|
||||||
public enum PrimitiveTypes
|
public enum PrimitiveTypes
|
||||||
{
|
{
|
||||||
@ -13,7 +14,8 @@ namespace Explorer
|
|||||||
Double,
|
Double,
|
||||||
Float,
|
Float,
|
||||||
Int,
|
Int,
|
||||||
String
|
String,
|
||||||
|
Char
|
||||||
}
|
}
|
||||||
|
|
||||||
private string m_valueToString;
|
private string m_valueToString;
|
||||||
@ -37,10 +39,10 @@ namespace Explorer
|
|||||||
t = typeof(float); break;
|
t = typeof(float); break;
|
||||||
case PrimitiveTypes.Int:
|
case PrimitiveTypes.Int:
|
||||||
t = typeof(int); break;
|
t = typeof(int); break;
|
||||||
case PrimitiveTypes.String:
|
case PrimitiveTypes.Char:
|
||||||
t = typeof(string); break;
|
t = typeof(char); break;
|
||||||
}
|
}
|
||||||
m_parseMethod = t.GetMethod("Parse", new Type[] { typeof(string) });
|
m_parseMethod = t?.GetMethod("Parse", new Type[] { typeof(string) });
|
||||||
}
|
}
|
||||||
return m_parseMethod;
|
return m_parseMethod;
|
||||||
}
|
}
|
||||||
@ -52,7 +54,7 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
if (Value == null)
|
if (Value == null)
|
||||||
{
|
{
|
||||||
// this must mean it is a string? no other primitive type should be nullable
|
// this must mean it is a string. No other primitive type should be nullable.
|
||||||
PrimitiveType = PrimitiveTypes.String;
|
PrimitiveType = PrimitiveTypes.String;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -72,21 +74,39 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
PrimitiveType = PrimitiveTypes.Float;
|
PrimitiveType = PrimitiveTypes.Float;
|
||||||
}
|
}
|
||||||
else if (type == typeof(int) || type == typeof(long) || type == typeof(uint) || type == typeof(ulong) || type == typeof(IntPtr))
|
else if (IsInteger(type))
|
||||||
{
|
{
|
||||||
PrimitiveType = PrimitiveTypes.Int;
|
PrimitiveType = PrimitiveTypes.Int;
|
||||||
}
|
}
|
||||||
|
else if (type == typeof(char))
|
||||||
|
{
|
||||||
|
PrimitiveType = PrimitiveTypes.Char;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (type != typeof(string))
|
|
||||||
{
|
|
||||||
MelonLogger.Log("Unsupported primitive: " + type);
|
|
||||||
}
|
|
||||||
|
|
||||||
PrimitiveType = PrimitiveTypes.String;
|
PrimitiveType = PrimitiveTypes.String;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsInteger(Type type)
|
||||||
|
{
|
||||||
|
// For our purposes, all types of int can be treated the same, including IntPtr.
|
||||||
|
return _integerTypes.Contains(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly HashSet<Type> _integerTypes = new HashSet<Type>
|
||||||
|
{
|
||||||
|
typeof(int),
|
||||||
|
typeof(uint),
|
||||||
|
typeof(short),
|
||||||
|
typeof(ushort),
|
||||||
|
typeof(long),
|
||||||
|
typeof(ulong),
|
||||||
|
typeof(byte),
|
||||||
|
typeof(sbyte),
|
||||||
|
typeof(IntPtr)
|
||||||
|
};
|
||||||
|
|
||||||
public override void UpdateValue()
|
public override void UpdateValue()
|
||||||
{
|
{
|
||||||
base.UpdateValue();
|
base.UpdateValue();
|
||||||
@ -99,9 +119,12 @@ namespace Explorer
|
|||||||
if (PrimitiveType == PrimitiveTypes.Bool)
|
if (PrimitiveType == PrimitiveTypes.Bool)
|
||||||
{
|
{
|
||||||
var b = (bool)Value;
|
var b = (bool)Value;
|
||||||
var color = "<color=" + (b ? "lime>" : "red>");
|
var color = $"<color={(b ? "lime>" : "red>")}";
|
||||||
b = GUILayout.Toggle(b, color + b.ToString() + "</color>", null);
|
var label = $"{color}{b}</color>";
|
||||||
|
|
||||||
|
if (CanWrite)
|
||||||
|
{
|
||||||
|
b = GUILayout.Toggle(b, label, null);
|
||||||
if (b != (bool)Value)
|
if (b != (bool)Value)
|
||||||
{
|
{
|
||||||
SetValue(m_valueToString);
|
SetValue(m_valueToString);
|
||||||
@ -109,16 +132,24 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GUILayout.Label("<color=yellow><i>" + PrimitiveType + "</i></color>", new GUILayoutOption[] { GUILayout.Width(50) });
|
GUILayout.Label(label, null);
|
||||||
|
}
|
||||||
var _width = window.width - 200;
|
|
||||||
if (m_valueToString.Length > 37)
|
|
||||||
{
|
|
||||||
m_valueToString = GUILayout.TextArea(m_valueToString, new GUILayoutOption[] { GUILayout.MaxWidth(_width) });
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_valueToString = GUILayout.TextField(m_valueToString, new GUILayoutOption[] { GUILayout.MaxWidth(_width) });
|
GUILayout.Label("<color=yellow><i>" + PrimitiveType + "</i></color>", new GUILayoutOption[] { GUILayout.Width(50) });
|
||||||
|
|
||||||
|
int dynSize = 25 + (m_valueToString.Length * 15);
|
||||||
|
var maxwidth = window.width - 300f;
|
||||||
|
if (CanWrite) maxwidth -= 60;
|
||||||
|
|
||||||
|
if (dynSize > maxwidth)
|
||||||
|
{
|
||||||
|
m_valueToString = GUILayout.TextArea(m_valueToString, new GUILayoutOption[] { GUILayout.MaxWidth(maxwidth) });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_valueToString = GUILayout.TextField(m_valueToString, new GUILayoutOption[] { GUILayout.MaxWidth(dynSize) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CanWrite)
|
if (CanWrite)
|
||||||
@ -128,6 +159,8 @@ namespace Explorer
|
|||||||
SetValue(m_valueToString);
|
SetValue(m_valueToString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUILayout.Space(5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using System.Reflection;
|
||||||
|
using Harmony;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
using UnhollowerBaseLib;
|
using UnhollowerBaseLib;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Explorer
|
namespace Explorer
|
||||||
{
|
{
|
||||||
public class CppExplorer : MelonMod
|
public class CppExplorer : MelonMod
|
||||||
{
|
{
|
||||||
// consts
|
public const string GUID = "com.sinai.cppexplorer";
|
||||||
|
public const string VERSION = "1.4.5";
|
||||||
public const string ID = "com.sinai.cppexplorer";
|
|
||||||
public const string VERSION = "1.4.2";
|
|
||||||
public const string AUTHOR = "Sinai";
|
public const string AUTHOR = "Sinai";
|
||||||
|
|
||||||
public const string NAME = "CppExplorer"
|
public const string NAME = "CppExplorer"
|
||||||
@ -22,26 +21,52 @@ namespace Explorer
|
|||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
// fields
|
public static CppExplorer Instance { get; private set; }
|
||||||
|
|
||||||
public static CppExplorer Instance;
|
public static bool ShowMenu
|
||||||
|
{
|
||||||
|
get => m_showMenu;
|
||||||
|
set => SetShowMenu(value);
|
||||||
|
}
|
||||||
|
private static bool m_showMenu;
|
||||||
|
|
||||||
// props
|
public static bool ForceUnlockMouse
|
||||||
|
{
|
||||||
|
get => m_forceUnlock;
|
||||||
|
set => SetForceUnlock(value);
|
||||||
|
}
|
||||||
|
private static bool m_forceUnlock;
|
||||||
|
private static CursorLockMode m_lastLockMode;
|
||||||
|
private static bool m_lastVisibleState;
|
||||||
|
private static bool m_currentlySettingCursor = false;
|
||||||
|
|
||||||
public static bool ShowMenu { get; set; } = false;
|
public static bool ShouldForceMouse => ShowMenu && ForceUnlockMouse;
|
||||||
|
|
||||||
// methods
|
private static void SetShowMenu(bool show)
|
||||||
|
{
|
||||||
|
m_showMenu = show;
|
||||||
|
UpdateCursorControl();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== MonoBehaviour methods ==========
|
||||||
|
|
||||||
public override void OnApplicationStart()
|
public override void OnApplicationStart()
|
||||||
{
|
{
|
||||||
base.OnApplicationStart();
|
|
||||||
|
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
|
||||||
new MainMenu();
|
new MainMenu();
|
||||||
new WindowManager();
|
new WindowManager();
|
||||||
|
|
||||||
ShowMenu = true;
|
// Get current cursor state and enable cursor
|
||||||
|
m_lastLockMode = Cursor.lockState;
|
||||||
|
m_lastVisibleState = Cursor.visible;
|
||||||
|
|
||||||
|
// Enable ShowMenu and ForceUnlockMouse
|
||||||
|
// (set m_showMenu to not call UpdateCursorState twice)
|
||||||
|
m_showMenu = true;
|
||||||
|
SetForceUnlock(true);
|
||||||
|
|
||||||
|
MelonLogger.Log($"CppExplorer {VERSION} initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnLevelWasLoaded(int level)
|
public override void OnLevelWasLoaded(int level)
|
||||||
@ -52,6 +77,7 @@ namespace Explorer
|
|||||||
|
|
||||||
public override void OnUpdate()
|
public override void OnUpdate()
|
||||||
{
|
{
|
||||||
|
// Check main toggle key input
|
||||||
if (Input.GetKeyDown(KeyCode.F7))
|
if (Input.GetKeyDown(KeyCode.F7))
|
||||||
{
|
{
|
||||||
ShowMenu = !ShowMenu;
|
ShowMenu = !ShowMenu;
|
||||||
@ -59,27 +85,115 @@ namespace Explorer
|
|||||||
|
|
||||||
if (ShowMenu)
|
if (ShowMenu)
|
||||||
{
|
{
|
||||||
if (!Cursor.visible)
|
// Check Force-Unlock input
|
||||||
|
if (Input.GetKeyDown(KeyCode.LeftAlt))
|
||||||
{
|
{
|
||||||
Cursor.visible = true;
|
ForceUnlockMouse = !ForceUnlockMouse;
|
||||||
Cursor.lockState = CursorLockMode.None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainMenu.Instance.Update();
|
MainMenu.Instance.Update();
|
||||||
WindowManager.Instance.Update();
|
WindowManager.Instance.Update();
|
||||||
|
|
||||||
InspectUnderMouse.Update();
|
InspectUnderMouse.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnGUI()
|
public override void OnGUI()
|
||||||
{
|
{
|
||||||
base.OnGUI();
|
|
||||||
|
|
||||||
MainMenu.Instance.OnGUI();
|
MainMenu.Instance.OnGUI();
|
||||||
WindowManager.Instance.OnGUI();
|
WindowManager.Instance.OnGUI();
|
||||||
|
|
||||||
InspectUnderMouse.OnGUI();
|
InspectUnderMouse.OnGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =========== Cursor control ===========
|
||||||
|
|
||||||
|
private static void SetForceUnlock(bool unlock)
|
||||||
|
{
|
||||||
|
m_forceUnlock = unlock;
|
||||||
|
UpdateCursorControl();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdateCursorControl()
|
||||||
|
{
|
||||||
|
m_currentlySettingCursor = true;
|
||||||
|
if (ShouldForceMouse)
|
||||||
|
{
|
||||||
|
Cursor.lockState = CursorLockMode.None;
|
||||||
|
Cursor.visible = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Cursor.lockState = m_lastLockMode;
|
||||||
|
Cursor.visible = m_lastVisibleState;
|
||||||
|
}
|
||||||
|
m_currentlySettingCursor = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force mouse to stay unlocked and visible while UnlockMouse and ShowMenu are true.
|
||||||
|
// Also keep track of when anything else tries to set Cursor state, this will be the
|
||||||
|
// value that we set back to when we close the menu or disable force-unlock.
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(Cursor), nameof(Cursor.lockState), MethodType.Setter)]
|
||||||
|
public class Cursor_lockState
|
||||||
|
{
|
||||||
|
[HarmonyPrefix]
|
||||||
|
public static void Prefix(ref CursorLockMode value)
|
||||||
|
{
|
||||||
|
if (!m_currentlySettingCursor)
|
||||||
|
{
|
||||||
|
m_lastLockMode = value;
|
||||||
|
|
||||||
|
if (ShouldForceMouse)
|
||||||
|
{
|
||||||
|
value = CursorLockMode.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(Cursor), nameof(Cursor.visible), MethodType.Setter)]
|
||||||
|
public class Cursor_set_visible
|
||||||
|
{
|
||||||
|
[HarmonyPrefix]
|
||||||
|
public static void Prefix(ref bool value)
|
||||||
|
{
|
||||||
|
if (!m_currentlySettingCursor)
|
||||||
|
{
|
||||||
|
m_lastVisibleState = value;
|
||||||
|
|
||||||
|
if (ShouldForceMouse)
|
||||||
|
{
|
||||||
|
value = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make it appear as though UnlockMouse is disabled to the rest of the application.
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(Cursor), nameof(Cursor.visible), MethodType.Getter)]
|
||||||
|
public class Cursor_get_visible
|
||||||
|
{
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void Postfix(ref bool __result)
|
||||||
|
{
|
||||||
|
if (ShouldForceMouse)
|
||||||
|
{
|
||||||
|
__result = m_lastVisibleState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(Cursor), nameof(Cursor.lockState), MethodType.Getter)]
|
||||||
|
public class Cursor_get_lockState
|
||||||
|
{
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void Postfix(ref CursorLockMode __result)
|
||||||
|
{
|
||||||
|
if (ShouldForceMouse)
|
||||||
|
{
|
||||||
|
__result = m_lastLockMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,6 @@
|
|||||||
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\Il2Cppmscorlib.dll</HintPath>
|
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\Il2Cppmscorlib.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Il2CppSystem.Core">
|
|
||||||
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\Il2CppSystem.Core.dll</HintPath>
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="mcs">
|
<Reference Include="mcs">
|
||||||
<HintPath>..\lib\mcs.dll</HintPath>
|
<HintPath>..\lib\mcs.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
@ -64,10 +60,6 @@
|
|||||||
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
|
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="UnhollowerRuntimeLib">
|
|
||||||
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnhollowerRuntimeLib.dll</HintPath>
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
<!-- Unity 2019 build (InputLegacyModule.dll) -->
|
<!-- Unity 2019 build (InputLegacyModule.dll) -->
|
||||||
<Reference Include="UnityEngine" Condition="'$(Configuration)'=='Debug'">
|
<Reference Include="UnityEngine" Condition="'$(Configuration)'=='Debug'">
|
||||||
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.dll</HintPath>
|
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.dll</HintPath>
|
||||||
@ -97,10 +89,6 @@
|
|||||||
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
|
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="UnityEngine.UIElementsModule" Condition="'$(Configuration)'=='Debug'">
|
|
||||||
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.UIElementsModule.dll</HintPath>
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
<!-- Unity 2018 build (InputModule.dll) -->
|
<!-- Unity 2018 build (InputModule.dll) -->
|
||||||
<Reference Include="UnityEngine" Condition="'$(Configuration)'=='Release_Unity2018'">
|
<Reference Include="UnityEngine" Condition="'$(Configuration)'=='Release_Unity2018'">
|
||||||
<HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.dll</HintPath>
|
<HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.dll</HintPath>
|
||||||
@ -130,17 +118,15 @@
|
|||||||
<HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
|
<HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="UnityEngine.UIElementsModule" Condition="'$(Configuration)'=='Release_Unity2018'">
|
|
||||||
<HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UIElementsModule.dll</HintPath>
|
|
||||||
<Private>False</Private>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="CachedObjects\CacheDictionary.cs" />
|
||||||
<Compile Include="CachedObjects\CacheEnum.cs" />
|
<Compile Include="CachedObjects\CacheEnum.cs" />
|
||||||
<Compile Include="CachedObjects\CacheGameObject.cs" />
|
<Compile Include="CachedObjects\CacheGameObject.cs" />
|
||||||
<Compile Include="CachedObjects\CacheList.cs" />
|
<Compile Include="CachedObjects\CacheList.cs" />
|
||||||
<Compile Include="CachedObjects\CachePrimitive.cs" />
|
<Compile Include="CachedObjects\CachePrimitive.cs" />
|
||||||
<Compile Include="CachedObjects\CacheOther.cs" />
|
<Compile Include="CachedObjects\CacheOther.cs" />
|
||||||
|
<Compile Include="CachedObjects\CacheMethod.cs" />
|
||||||
<Compile Include="CppExplorer.cs" />
|
<Compile Include="CppExplorer.cs" />
|
||||||
<Compile Include="Extensions\ReflectionExtensions.cs" />
|
<Compile Include="Extensions\ReflectionExtensions.cs" />
|
||||||
<Compile Include="Extensions\UnityExtensions.cs" />
|
<Compile Include="Extensions\UnityExtensions.cs" />
|
||||||
@ -148,7 +134,9 @@
|
|||||||
<Compile Include="Helpers\UIHelpers.cs" />
|
<Compile Include="Helpers\UIHelpers.cs" />
|
||||||
<Compile Include="Helpers\UnityHelpers.cs" />
|
<Compile Include="Helpers\UnityHelpers.cs" />
|
||||||
<Compile Include="MainMenu\InspectUnderMouse.cs" />
|
<Compile Include="MainMenu\InspectUnderMouse.cs" />
|
||||||
<Compile Include="CachedObjects\CacheObject.cs" />
|
<Compile Include="CachedObjects\CacheObjectBase.cs" />
|
||||||
|
<Compile Include="Windows\ResizeDrag.cs" />
|
||||||
|
<Compile Include="Windows\TabViewWindow.cs" />
|
||||||
<Compile Include="Windows\UIWindow.cs" />
|
<Compile Include="Windows\UIWindow.cs" />
|
||||||
<Compile Include="MainMenu\Pages\ConsolePage.cs" />
|
<Compile Include="MainMenu\Pages\ConsolePage.cs" />
|
||||||
<Compile Include="MainMenu\Pages\Console\REPL.cs" />
|
<Compile Include="MainMenu\Pages\Console\REPL.cs" />
|
||||||
|
@ -8,15 +8,12 @@ using UnhollowerBaseLib;
|
|||||||
using UnhollowerRuntimeLib;
|
using UnhollowerRuntimeLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using BF = System.Reflection.BindingFlags;
|
using BF = System.Reflection.BindingFlags;
|
||||||
using ILBF = Il2CppSystem.Reflection.BindingFlags;
|
|
||||||
using MelonLoader;
|
|
||||||
|
|
||||||
namespace Explorer
|
namespace Explorer
|
||||||
{
|
{
|
||||||
public class ReflectionHelpers
|
public class ReflectionHelpers
|
||||||
{
|
{
|
||||||
public static BF CommonFlags = BF.Public | BF.Instance | BF.NonPublic | BF.Static;
|
public static BF CommonFlags = BF.Public | BF.Instance | BF.NonPublic | BF.Static;
|
||||||
public static ILBF CommonFlags_IL = ILBF.Public | ILBF.NonPublic | ILBF.Instance | ILBF.Static;
|
|
||||||
|
|
||||||
public static Il2CppSystem.Type GameObjectType => Il2CppType.Of<GameObject>();
|
public static Il2CppSystem.Type GameObjectType => Il2CppType.Of<GameObject>();
|
||||||
public static Il2CppSystem.Type TransformType => Il2CppType.Of<Transform>();
|
public static Il2CppSystem.Type TransformType => Il2CppType.Of<Transform>();
|
||||||
@ -75,6 +72,11 @@ namespace Explorer
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsArray(Type t)
|
||||||
|
{
|
||||||
|
return typeof(System.Collections.IEnumerable).IsAssignableFrom(t);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsList(Type t)
|
public static bool IsList(Type t)
|
||||||
{
|
{
|
||||||
return t.IsGenericType
|
return t.IsGenericType
|
||||||
@ -82,6 +84,13 @@ namespace Explorer
|
|||||||
&& (typeDef.IsAssignableFrom(typeof(List<>)) || typeDef.IsAssignableFrom(typeof(Il2CppSystem.Collections.Generic.List<>)));
|
&& (typeDef.IsAssignableFrom(typeof(List<>)) || typeDef.IsAssignableFrom(typeof(Il2CppSystem.Collections.Generic.List<>)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsDictionary(Type t)
|
||||||
|
{
|
||||||
|
return t.IsGenericType
|
||||||
|
&& t.GetGenericTypeDefinition() is Type typeDef
|
||||||
|
&& typeDef.IsAssignableFrom(typeof(Il2CppSystem.Collections.Generic.Dictionary<,>));
|
||||||
|
}
|
||||||
|
|
||||||
public static Type GetTypeByName(string typeName)
|
public static Type GetTypeByName(string typeName)
|
||||||
{
|
{
|
||||||
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
|
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
|
||||||
|
@ -69,8 +69,8 @@ namespace Explorer
|
|||||||
var newSkin = Object.Instantiate(GUI.skin);
|
var newSkin = Object.Instantiate(GUI.skin);
|
||||||
Object.DontDestroyOnLoad(newSkin);
|
Object.DontDestroyOnLoad(newSkin);
|
||||||
|
|
||||||
m_nofocusTex = MakeTex(550, 700, new Color(0.1f, 0.1f, 0.1f, 0.7f));
|
m_nofocusTex = MakeTex(1, 1, new Color(0.1f, 0.1f, 0.1f, 0.7f));
|
||||||
m_focusTex = MakeTex(550, 700, new Color(0.3f, 0.3f, 0.3f, 1f));
|
m_focusTex = MakeTex(1, 1, new Color(0.3f, 0.3f, 0.3f, 1f));
|
||||||
|
|
||||||
newSkin.window.normal.background = m_nofocusTex;
|
newSkin.window.normal.background = m_nofocusTex;
|
||||||
newSkin.window.onNormal.background = m_focusTex;
|
newSkin.window.onNormal.background = m_focusTex;
|
||||||
|
@ -81,7 +81,7 @@ namespace Explorer
|
|||||||
page.DrawWindow();
|
page.DrawWindow();
|
||||||
GUILayout.EndScrollView();
|
GUILayout.EndScrollView();
|
||||||
|
|
||||||
MainRect = WindowManager.ResizeWindow(MainRect, MainWindowID);
|
MainRect = ResizeDrag.ResizeWindow(MainRect, MainWindowID);
|
||||||
|
|
||||||
GUILayout.EndArea();
|
GUILayout.EndArea();
|
||||||
}
|
}
|
||||||
@ -103,9 +103,17 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
GUILayout.BeginHorizontal(null);
|
||||||
GUI.color = Color.white;
|
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)", null);
|
||||||
|
|
||||||
|
bool mouseState = CppExplorer.ForceUnlockMouse;
|
||||||
|
bool setMouse = GUILayout.Toggle(mouseState, "Force Unlock Mouse (Left Alt)", null);
|
||||||
|
if (setMouse != mouseState) CppExplorer.ForceUnlockMouse = setMouse;
|
||||||
|
|
||||||
|
WindowManager.TabView = GUILayout.Toggle(WindowManager.TabView, "Tab View", null);
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
GUILayout.Space(10);
|
GUILayout.Space(10);
|
||||||
GUI.color = Color.white;
|
GUI.color = Color.white;
|
||||||
}
|
}
|
||||||
|
@ -86,11 +86,11 @@ MelonLogger.Log(""hello world"");";
|
|||||||
if (!UsingDirectives.Contains(asm))
|
if (!UsingDirectives.Contains(asm))
|
||||||
{
|
{
|
||||||
UsingDirectives.Add(asm);
|
UsingDirectives.Add(asm);
|
||||||
Evaluate(AsmToUsing(asm));
|
Evaluate(AsmToUsing(asm), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Evaluate(string str)
|
public object Evaluate(string str, bool suppressWarning = false)
|
||||||
{
|
{
|
||||||
object ret = VoidType.Value;
|
object ret = VoidType.Value;
|
||||||
|
|
||||||
@ -98,11 +98,19 @@ MelonLogger.Log(""hello world"");";
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
compiled?.Invoke(ref ret);
|
if (compiled == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Mono.Csharp Service was unable to compile the code provided.");
|
||||||
|
}
|
||||||
|
|
||||||
|
compiled.Invoke(ref ret);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
MelonLogger.LogWarning(e.ToString());
|
if (!suppressWarning)
|
||||||
|
{
|
||||||
|
MelonLogger.LogWarning(e.GetType() + ", " + e.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -113,8 +121,10 @@ MelonLogger.Log(""hello world"");";
|
|||||||
{
|
{
|
||||||
GUILayout.Label("<b><size=15><color=cyan>C# REPL Console</color></size></b>", null);
|
GUILayout.Label("<b><size=15><color=cyan>C# REPL Console</color></size></b>", null);
|
||||||
|
|
||||||
GUILayout.Label("Method:", null);
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||||
MethodInput = GUILayout.TextArea(MethodInput, new GUILayoutOption[] { GUILayout.Height(300) });
|
|
||||||
|
GUILayout.Label("Enter code here as though it is a method body:", null);
|
||||||
|
MethodInput = GUILayout.TextArea(MethodInput, new GUILayoutOption[] { GUILayout.Height(250) });
|
||||||
|
|
||||||
if (GUILayout.Button("<color=cyan><b>Execute</b></color>", null))
|
if (GUILayout.Button("<color=cyan><b>Execute</b></color>", null))
|
||||||
{
|
{
|
||||||
@ -139,12 +149,9 @@ MelonLogger.Log(""hello world"");";
|
|||||||
}
|
}
|
||||||
|
|
||||||
GUILayout.Label("<b>Using directives:</b>", null);
|
GUILayout.Label("<b>Using directives:</b>", null);
|
||||||
foreach (var asm in UsingDirectives)
|
|
||||||
{
|
|
||||||
GUILayout.Label(AsmToUsing(asm, true), null);
|
|
||||||
}
|
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
GUILayout.Label("Add namespace:", new GUILayoutOption[] { GUILayout.Width(110) });
|
GUILayout.Label("Add namespace:", new GUILayoutOption[] { GUILayout.Width(105) });
|
||||||
UsingInput = GUILayout.TextField(UsingInput, new GUILayoutOption[] { GUILayout.Width(150) });
|
UsingInput = GUILayout.TextField(UsingInput, new GUILayoutOption[] { GUILayout.Width(150) });
|
||||||
if (GUILayout.Button("<b><color=lime>Add</color></b>", new GUILayoutOption[] { GUILayout.Width(120) }))
|
if (GUILayout.Button("<b><color=lime>Add</color></b>", new GUILayoutOption[] { GUILayout.Width(120) }))
|
||||||
{
|
{
|
||||||
@ -155,6 +162,11 @@ MelonLogger.Log(""hello world"");";
|
|||||||
ResetConsole();
|
ResetConsole();
|
||||||
}
|
}
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
foreach (var asm in UsingDirectives)
|
||||||
|
{
|
||||||
|
GUILayout.Label(AsmToUsing(asm, true), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update() { }
|
public override void Update() { }
|
||||||
|
@ -26,7 +26,7 @@ namespace Explorer
|
|||||||
//private List<object> m_searchResults = new List<object>();
|
//private List<object> m_searchResults = new List<object>();
|
||||||
private Vector2 resultsScroll = Vector2.zero;
|
private Vector2 resultsScroll = Vector2.zero;
|
||||||
|
|
||||||
private List<CacheObject> m_searchResults = new List<CacheObject>();
|
private List<CacheObjectBase> m_searchResults = new List<CacheObjectBase>();
|
||||||
|
|
||||||
public SceneFilter SceneMode = SceneFilter.Any;
|
public SceneFilter SceneMode = SceneFilter.Any;
|
||||||
public TypeFilter TypeMode = TypeFilter.Object;
|
public TypeFilter TypeMode = TypeFilter.Object;
|
||||||
@ -64,7 +64,7 @@ namespace Explorer
|
|||||||
|
|
||||||
private void CacheResults(IEnumerable results)
|
private void CacheResults(IEnumerable results)
|
||||||
{
|
{
|
||||||
m_searchResults = new List<CacheObject>();
|
m_searchResults = new List<CacheObjectBase>();
|
||||||
|
|
||||||
foreach (var obj in results)
|
foreach (var obj in results)
|
||||||
{
|
{
|
||||||
@ -75,7 +75,7 @@ namespace Explorer
|
|||||||
toCache = ilObject.TryCast<GameObject>() ?? ilObject.TryCast<Transform>()?.gameObject ?? ilObject;
|
toCache = ilObject.TryCast<GameObject>() ?? ilObject.TryCast<Transform>()?.gameObject ?? ilObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cache = CacheObject.GetCacheObject(toCache);
|
var cache = CacheObjectBase.GetCacheObject(toCache);
|
||||||
m_searchResults.Add(cache);
|
m_searchResults.Add(cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,9 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
public class GameObjectWindow : UIWindow
|
public class GameObjectWindow : UIWindow
|
||||||
{
|
{
|
||||||
public override string Name { get => "GameObject Inspector"; set => Name = value; }
|
public override string Title => WindowManager.TabView
|
||||||
|
? $"<color=cyan>[G]</color> {m_object.name}"
|
||||||
|
: $"GameObject Inspector ({m_object.name})";
|
||||||
|
|
||||||
public GameObject m_object;
|
public GameObject m_object;
|
||||||
|
|
||||||
@ -21,18 +23,18 @@ namespace Explorer
|
|||||||
|
|
||||||
private Vector2 m_transformScroll = Vector2.zero;
|
private Vector2 m_transformScroll = Vector2.zero;
|
||||||
private Transform[] m_children;
|
private Transform[] m_children;
|
||||||
|
private Component[] m_components;
|
||||||
|
|
||||||
private Vector2 m_compScroll = Vector2.zero;
|
private Vector2 m_compScroll = Vector2.zero;
|
||||||
//private Component[] m_components;
|
|
||||||
|
|
||||||
private float m_translateAmount = 0.3f;
|
private float m_translateAmount = 0.3f;
|
||||||
private float m_rotateAmount = 50f;
|
private float m_rotateAmount = 50f;
|
||||||
private float m_scaleAmount = 0.1f;
|
private float m_scaleAmount = 0.1f;
|
||||||
|
|
||||||
private List<Component> m_cachedDestroyList = new List<Component>();
|
private readonly List<Component> m_cachedDestroyList = new List<Component>();
|
||||||
//private string m_addComponentInput = "";
|
//private string m_addComponentInput = "";
|
||||||
|
|
||||||
private string m_setParentInput = "";
|
private string m_setParentInput = "Enter a GameObject name or path";
|
||||||
|
|
||||||
public bool GetObjectAsGameObject()
|
public bool GetObjectAsGameObject()
|
||||||
{
|
{
|
||||||
@ -68,11 +70,9 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_name = m_object.name;
|
m_name = m_object.name;
|
||||||
m_scene = m_object.scene == null ? "null" : m_object.scene.name;
|
m_scene = string.IsNullOrEmpty(m_object.scene.name)
|
||||||
|
? "None"
|
||||||
//var listComps = new Il2CppSystem.Collections.Generic.List<Component>();
|
: m_object.scene.name;
|
||||||
//m_object.GetComponents(listComps);
|
|
||||||
//m_components = listComps.ToArray();
|
|
||||||
|
|
||||||
var list = new List<Transform>();
|
var list = new List<Transform>();
|
||||||
for (int i = 0; i < m_object.transform.childCount; i++)
|
for (int i = 0; i < m_object.transform.childCount; i++)
|
||||||
@ -83,12 +83,31 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (!m_object && !GetObjectAsGameObject())
|
if (!m_object && !GetObjectAsGameObject())
|
||||||
{
|
{
|
||||||
MelonLogger.Log("Object is null! Destroying window...");
|
throw new Exception("Object is null!");
|
||||||
DestroyWindow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var list = new List<Component>();
|
||||||
|
foreach (var comp in m_object.GetComponents(ReflectionHelpers.ComponentType))
|
||||||
|
{
|
||||||
|
list.Add(comp);
|
||||||
|
}
|
||||||
|
m_components = list.ToArray();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
DestroyOnException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DestroyOnException(Exception e)
|
||||||
|
{
|
||||||
|
MelonLogger.Log($"{e.GetType()}, {e.Message}");
|
||||||
|
DestroyWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InspectGameObject(Transform obj)
|
private void InspectGameObject(Transform obj)
|
||||||
@ -125,9 +144,15 @@ namespace Explorer
|
|||||||
|
|
||||||
public override void WindowFunction(int windowID)
|
public override void WindowFunction(int windowID)
|
||||||
{
|
{
|
||||||
Header();
|
try
|
||||||
|
{
|
||||||
|
var rect = WindowManager.TabView ? TabViewWindow.Instance.m_rect : this.m_rect;
|
||||||
|
|
||||||
GUILayout.BeginArea(new Rect(5, 25, m_rect.width - 10, m_rect.height - 35), GUI.skin.box);
|
if (!WindowManager.TabView)
|
||||||
|
{
|
||||||
|
Header();
|
||||||
|
GUILayout.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
|
||||||
|
}
|
||||||
|
|
||||||
scroll = GUILayout.BeginScrollView(scroll, GUI.skin.scrollView);
|
scroll = GUILayout.BeginScrollView(scroll, GUI.skin.scrollView);
|
||||||
|
|
||||||
@ -164,12 +189,12 @@ namespace Explorer
|
|||||||
// --- Horizontal Columns section ---
|
// --- Horizontal Columns section ---
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
|
|
||||||
GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 17) });
|
GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(rect.width / 2 - 17) });
|
||||||
TransformList();
|
TransformList(rect);
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
|
|
||||||
GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 17) });
|
GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(rect.width / 2 - 17) });
|
||||||
ComponentList();
|
ComponentList(rect);
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
|
|
||||||
GUILayout.EndHorizontal(); // end horiz columns
|
GUILayout.EndHorizontal(); // end horiz columns
|
||||||
@ -178,14 +203,22 @@ namespace Explorer
|
|||||||
|
|
||||||
GUILayout.EndScrollView();
|
GUILayout.EndScrollView();
|
||||||
|
|
||||||
m_rect = WindowManager.ResizeWindow(m_rect, windowID);
|
if (!WindowManager.TabView)
|
||||||
|
{
|
||||||
|
m_rect = ResizeDrag.ResizeWindow(rect, windowID);
|
||||||
|
|
||||||
GUILayout.EndArea();
|
GUILayout.EndArea();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void TransformList()
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
GUILayout.BeginVertical(GUI.skin.box, new GUILayoutOption[] { GUILayout.Height(250) });
|
DestroyOnException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TransformList(Rect m_rect)
|
||||||
|
{
|
||||||
|
GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) });
|
||||||
m_transformScroll = GUILayout.BeginScrollView(m_transformScroll, GUI.skin.scrollView);
|
m_transformScroll = GUILayout.BeginScrollView(m_transformScroll, GUI.skin.scrollView);
|
||||||
|
|
||||||
GUILayout.Label("<b>Children:</b>", null);
|
GUILayout.Label("<b>Children:</b>", null);
|
||||||
@ -198,7 +231,7 @@ namespace Explorer
|
|||||||
GUILayout.Label("null", null);
|
GUILayout.Label("null", null);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
UIHelpers.GameobjButton(obj.gameObject, InspectGameObject, false, this.m_rect.width / 2 - 60);
|
UIHelpers.GameobjButton(obj.gameObject, InspectGameObject, false, m_rect.width / 2 - 60);
|
||||||
}
|
}
|
||||||
foreach (var obj in m_children.Where(x => x.childCount == 0))
|
foreach (var obj in m_children.Where(x => x.childCount == 0))
|
||||||
{
|
{
|
||||||
@ -207,7 +240,7 @@ namespace Explorer
|
|||||||
GUILayout.Label("null", null);
|
GUILayout.Label("null", null);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
UIHelpers.GameobjButton(obj.gameObject, InspectGameObject, false, this.m_rect.width / 2 - 60);
|
UIHelpers.GameobjButton(obj.gameObject, InspectGameObject, false, m_rect.width / 2 - 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -220,9 +253,9 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ComponentList()
|
private void ComponentList(Rect m_rect)
|
||||||
{
|
{
|
||||||
GUILayout.BeginVertical(GUI.skin.box, new GUILayoutOption[] { GUILayout.Height(250) });
|
GUILayout.BeginVertical(GUI.skin.box, null); // new GUILayoutOption[] { GUILayout.Height(250) });
|
||||||
m_compScroll = GUILayout.BeginScrollView(m_compScroll, GUI.skin.scrollView);
|
m_compScroll = GUILayout.BeginScrollView(m_compScroll, GUI.skin.scrollView);
|
||||||
GUILayout.Label("<b><size=15>Components</size></b>", null);
|
GUILayout.Label("<b><size=15>Components</size></b>", null);
|
||||||
|
|
||||||
@ -232,11 +265,12 @@ namespace Explorer
|
|||||||
m_cachedDestroyList.Clear();
|
m_cachedDestroyList.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
var m_components = new Il2CppSystem.Collections.Generic.List<Component>();
|
if (m_components != null)
|
||||||
m_object.GetComponentsInternal(Il2CppType.Of<Component>(), false, false, true, false, m_components);
|
{
|
||||||
|
|
||||||
foreach (var component in m_components)
|
foreach (var component in m_components)
|
||||||
{
|
{
|
||||||
|
if (!component) continue;
|
||||||
|
|
||||||
var ilType = component.GetIl2CppType();
|
var ilType = component.GetIl2CppType();
|
||||||
if (ilType == ReflectionHelpers.TransformType)
|
if (ilType == ReflectionHelpers.TransformType)
|
||||||
{
|
{
|
||||||
@ -248,6 +282,10 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
BehaviourEnabledBtn(component.TryCast<Behaviour>());
|
BehaviourEnabledBtn(component.TryCast<Behaviour>());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUILayout.Space(26);
|
||||||
|
}
|
||||||
if (GUILayout.Button("<color=cyan>" + ilType.Name + "</color>", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 90) }))
|
if (GUILayout.Button("<color=cyan>" + ilType.Name + "</color>", new GUILayoutOption[] { GUILayout.Width(m_rect.width / 2 - 90) }))
|
||||||
{
|
{
|
||||||
ReflectObject(component);
|
ReflectObject(component);
|
||||||
@ -258,7 +296,7 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
||||||
if (m_cachedDestroyList.Count > 0)
|
if (m_cachedDestroyList.Count > 0)
|
||||||
@ -300,7 +338,7 @@ namespace Explorer
|
|||||||
|
|
||||||
private void GameObjectControls()
|
private void GameObjectControls()
|
||||||
{
|
{
|
||||||
GUILayout.BeginVertical(GUI.skin.box, new GUILayoutOption[] { GUILayout.Width(530) });
|
GUILayout.BeginVertical(GUI.skin.box, new GUILayoutOption[] { GUILayout.Width(520) });
|
||||||
GUILayout.Label("<b><size=15>GameObject Controls</size></b>", null);
|
GUILayout.Label("<b><size=15>GameObject Controls</size></b>", null);
|
||||||
|
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
@ -311,15 +349,16 @@ namespace Explorer
|
|||||||
|
|
||||||
UIHelpers.InstantiateButton(m_object, 100);
|
UIHelpers.InstantiateButton(m_object, 100);
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
if (GUILayout.Button("Set DontDestroyOnLoad", new GUILayoutOption[] { GUILayout.Width(170) }))
|
||||||
|
{
|
||||||
|
GameObject.DontDestroyOnLoad(m_object);
|
||||||
|
m_object.hideFlags |= HideFlags.DontUnloadUnusedAsset;
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
|
|
||||||
if (GUILayout.Button("Remove from parent", new GUILayoutOption[] { GUILayout.Width(160) }))
|
m_setParentInput = GUILayout.TextField(m_setParentInput, null);
|
||||||
{
|
|
||||||
m_object.transform.parent = null;
|
|
||||||
}
|
|
||||||
m_setParentInput = GUILayout.TextField(m_setParentInput, new GUILayoutOption[] { GUILayout.Width(m_rect.width - 280) });
|
|
||||||
if (GUILayout.Button("Set Parent", new GUILayoutOption[] { GUILayout.Width(80) }))
|
if (GUILayout.Button("Set Parent", new GUILayoutOption[] { GUILayout.Width(80) }))
|
||||||
{
|
{
|
||||||
if (GameObject.Find(m_setParentInput) is GameObject newparent)
|
if (GameObject.Find(m_setParentInput) is GameObject newparent)
|
||||||
@ -331,6 +370,11 @@ namespace Explorer
|
|||||||
MelonLogger.LogWarning($"Could not find gameobject '{m_setParentInput}'");
|
MelonLogger.LogWarning($"Could not find gameobject '{m_setParentInput}'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GUILayout.Button("Detach from parent", new GUILayoutOption[] { GUILayout.Width(160) }))
|
||||||
|
{
|
||||||
|
m_object.transform.parent = null;
|
||||||
|
}
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
GUILayout.BeginVertical(GUI.skin.box, null);
|
GUILayout.BeginVertical(GUI.skin.box, null);
|
||||||
@ -342,7 +386,7 @@ namespace Explorer
|
|||||||
|
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
|
|
||||||
if (GUILayout.Button("<color=red><b>Destroy</b></color>", null))
|
if (GUILayout.Button("<color=red><b>Destroy</b></color>", new GUILayoutOption[] { GUILayout.Width(120) }))
|
||||||
{
|
{
|
||||||
GameObject.Destroy(m_object);
|
GameObject.Destroy(m_object);
|
||||||
DestroyWindow();
|
DestroyWindow();
|
||||||
|
@ -5,7 +5,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
using Mono.CSharp;
|
|
||||||
using UnhollowerBaseLib;
|
using UnhollowerBaseLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -13,34 +12,33 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
public class ReflectionWindow : UIWindow
|
public class ReflectionWindow : UIWindow
|
||||||
{
|
{
|
||||||
public override string Name { get => "Object Reflection"; set => Name = value; }
|
public override string Title => WindowManager.TabView
|
||||||
|
? $"<color=cyan>[R]</color> {ObjectType.Name}"
|
||||||
|
: $"Reflection Inspector ({ObjectType.Name})";
|
||||||
|
|
||||||
public Type ObjectType;
|
public Type ObjectType;
|
||||||
|
|
||||||
private CacheObject[] m_cachedMembers;
|
private CacheObjectBase[] m_allCachedMembers;
|
||||||
private CacheObject[] m_cachedMemberFiltered;
|
private CacheObjectBase[] m_cachedMembersFiltered;
|
||||||
private int m_pageOffset;
|
private int m_pageOffset;
|
||||||
private int m_limitPerPage = 20;
|
private int m_limitPerPage = 20;
|
||||||
|
|
||||||
private bool m_autoUpdate = false;
|
private bool m_autoUpdate = false;
|
||||||
private string m_search = "";
|
private string m_search = "";
|
||||||
public MemberInfoType m_filter = MemberInfoType.Property;
|
public MemberTypes m_filter = MemberTypes.Property;
|
||||||
private bool m_hideFailedReflection = false;
|
private bool m_hideFailedReflection = false;
|
||||||
|
|
||||||
public enum MemberInfoType
|
// some extra caching
|
||||||
{
|
private UnityEngine.Object m_uObj;
|
||||||
Field,
|
private Component m_component;
|
||||||
Property,
|
|
||||||
Method,
|
|
||||||
All
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init()
|
public override void Init()
|
||||||
{
|
{
|
||||||
var type = ReflectionHelpers.GetActualType(Target);
|
var type = ReflectionHelpers.GetActualType(Target);
|
||||||
if (type == null)
|
if (type == null)
|
||||||
{
|
{
|
||||||
MelonLogger.Log("Could not get underlying type for object. ToString(): " + Target.ToString());
|
MelonLogger.Log($"Could not get underlying type for object..? Type: {Target?.GetType().Name}, ToString: {Target?.ToString()}");
|
||||||
|
DestroyWindow();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,15 +47,32 @@ namespace Explorer
|
|||||||
var types = ReflectionHelpers.GetAllBaseTypes(Target);
|
var types = ReflectionHelpers.GetAllBaseTypes(Target);
|
||||||
CacheMembers(types);
|
CacheMembers(types);
|
||||||
|
|
||||||
m_filter = MemberInfoType.All;
|
if (Target is Il2CppSystem.Object ilObject)
|
||||||
m_cachedMemberFiltered = m_cachedMembers.Where(x => ShouldProcessMember(x)).ToArray();
|
{
|
||||||
UpdateValues();
|
var unityObj = ilObject.TryCast<UnityEngine.Object>();
|
||||||
m_filter = MemberInfoType.Property;
|
if (unityObj)
|
||||||
|
{
|
||||||
|
m_uObj = unityObj;
|
||||||
|
|
||||||
|
var component = ilObject.TryCast<Component>();
|
||||||
|
if (component)
|
||||||
|
{
|
||||||
|
m_component = component;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_filter = MemberTypes.All;
|
||||||
|
m_autoUpdate = true;
|
||||||
|
Update();
|
||||||
|
|
||||||
|
m_autoUpdate = false;
|
||||||
|
m_filter = MemberTypes.Property;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
m_cachedMemberFiltered = m_cachedMembers.Where(x => ShouldProcessMember(x)).ToArray();
|
m_cachedMembersFiltered = m_allCachedMembers.Where(x => ShouldProcessMember(x)).ToArray();
|
||||||
|
|
||||||
if (m_autoUpdate)
|
if (m_autoUpdate)
|
||||||
{
|
{
|
||||||
@ -67,20 +82,15 @@ namespace Explorer
|
|||||||
|
|
||||||
private void UpdateValues()
|
private void UpdateValues()
|
||||||
{
|
{
|
||||||
UpdateMembers();
|
foreach (var member in m_cachedMembersFiltered)
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateMembers()
|
|
||||||
{
|
|
||||||
foreach (var member in m_cachedMemberFiltered)
|
|
||||||
{
|
{
|
||||||
member.UpdateValue();
|
member.UpdateValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ShouldProcessMember(CacheObject holder)
|
private bool ShouldProcessMember(CacheObjectBase holder)
|
||||||
{
|
{
|
||||||
if (m_filter != MemberInfoType.All && m_filter != holder.MemberInfoType) return false;
|
if (m_filter != MemberTypes.All && m_filter != holder.MemberInfo?.MemberType) return false;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(holder.ReflectionException) && m_hideFailedReflection) return false;
|
if (!string.IsNullOrEmpty(holder.ReflectionException) && m_hideFailedReflection) return false;
|
||||||
|
|
||||||
@ -93,16 +103,13 @@ namespace Explorer
|
|||||||
|
|
||||||
private void CacheMembers(Type[] types)
|
private void CacheMembers(Type[] types)
|
||||||
{
|
{
|
||||||
var list = new List<CacheObject>();
|
var list = new List<CacheObjectBase>();
|
||||||
|
|
||||||
var names = new List<string>();
|
var names = new List<string>();
|
||||||
|
|
||||||
foreach (var declaringType in types)
|
foreach (var declaringType in types)
|
||||||
{
|
{
|
||||||
if (declaringType == typeof(Il2CppObjectBase)) continue;
|
|
||||||
|
|
||||||
MemberInfo[] infos;
|
MemberInfo[] infos;
|
||||||
|
|
||||||
string exception = null;
|
string exception = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -115,8 +122,8 @@ namespace Explorer
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//object value = null;
|
|
||||||
object target = Target;
|
object target = Target;
|
||||||
|
|
||||||
if (target is Il2CppSystem.Object ilObject)
|
if (target is Il2CppSystem.Object ilObject)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -131,9 +138,10 @@ namespace Explorer
|
|||||||
|
|
||||||
foreach (var member in infos)
|
foreach (var member in infos)
|
||||||
{
|
{
|
||||||
if (member.MemberType == MemberTypes.Field || member.MemberType == MemberTypes.Property)
|
if (member.MemberType == MemberTypes.Field || member.MemberType == MemberTypes.Property || member.MemberType == MemberTypes.Method)
|
||||||
{
|
{
|
||||||
if (member.Name == "Il2CppType") continue;
|
if (member.Name.Contains("Il2CppType") || member.Name.StartsWith("get_") || member.Name.StartsWith("set_"))
|
||||||
|
continue;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -141,7 +149,7 @@ namespace Explorer
|
|||||||
if (names.Contains(name)) continue;
|
if (names.Contains(name)) continue;
|
||||||
names.Add(name);
|
names.Add(name);
|
||||||
|
|
||||||
var cached = CacheObject.GetCacheObject(null, member, target);
|
var cached = CacheObjectBase.GetCacheObject(null, member, target);
|
||||||
if (cached != null)
|
if (cached != null)
|
||||||
{
|
{
|
||||||
list.Add(cached);
|
list.Add(cached);
|
||||||
@ -150,15 +158,14 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
MelonLogger.Log("Exception caching member!");
|
MelonLogger.LogWarning($"Exception caching member {declaringType.Name}.{member.Name}!");
|
||||||
MelonLogger.Log(e.GetType() + ", " + e.Message);
|
MelonLogger.Log(e.ToString());
|
||||||
MelonLogger.Log(e.StackTrace);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cachedMembers = list.ToArray();
|
m_allCachedMembers = list.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========== GUI DRAW =========== //
|
// =========== GUI DRAW =========== //
|
||||||
@ -167,40 +174,42 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Header();
|
// ====== HEADER ======
|
||||||
|
|
||||||
GUILayout.BeginArea(new Rect(5, 25, m_rect.width - 10, m_rect.height - 35), GUI.skin.box);
|
var rect = WindowManager.TabView ? TabViewWindow.Instance.m_rect : this.m_rect;
|
||||||
|
|
||||||
|
if (!WindowManager.TabView)
|
||||||
|
{
|
||||||
|
Header();
|
||||||
|
GUILayout.BeginArea(new Rect(5, 25, rect.width - 10, rect.height - 35), GUI.skin.box);
|
||||||
|
}
|
||||||
|
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
GUILayout.Label("<b>Type:</b> <color=cyan>" + ObjectType.FullName + "</color>", null);
|
GUILayout.Label("<b>Type:</b> <color=cyan>" + ObjectType.FullName + "</color>", new GUILayoutOption[] { GUILayout.Width(245f) });
|
||||||
|
if (m_uObj)
|
||||||
bool unityObj = Target is UnityEngine.Object;
|
|
||||||
|
|
||||||
if (unityObj)
|
|
||||||
{
|
{
|
||||||
GUILayout.Label("Name: " + (Target as UnityEngine.Object).name, null);
|
GUILayout.Label("Name: " + m_uObj.name, null);
|
||||||
}
|
}
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
if (unityObj)
|
if (m_uObj)
|
||||||
{
|
{
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
|
|
||||||
GUILayout.Label("<b>Tools:</b>", new GUILayoutOption[] { GUILayout.Width(80) });
|
GUILayout.Label("<b>Tools:</b>", new GUILayoutOption[] { GUILayout.Width(80) });
|
||||||
|
UIHelpers.InstantiateButton(m_uObj);
|
||||||
UIHelpers.InstantiateButton((UnityEngine.Object)Target);
|
if (m_component && m_component.gameObject is GameObject obj)
|
||||||
|
|
||||||
if (Target is Component comp && comp.gameObject is GameObject obj)
|
|
||||||
{
|
{
|
||||||
GUI.skin.label.alignment = TextAnchor.MiddleRight;
|
GUI.skin.label.alignment = TextAnchor.MiddleRight;
|
||||||
GUILayout.Label("GameObject:", null);
|
GUILayout.Label("GameObject:", new GUILayoutOption[] { GUILayout.Width(135) });
|
||||||
if (GUILayout.Button("<color=#00FF00>" + obj.name + "</color>", new GUILayoutOption[] { GUILayout.MaxWidth(m_rect.width - 350) }))
|
var charWidth = obj.name.Length * 15;
|
||||||
|
var maxWidth = rect.width - 350;
|
||||||
|
var labelWidth = charWidth < maxWidth ? charWidth : maxWidth;
|
||||||
|
if (GUILayout.Button("<color=#00FF00>" + obj.name + "</color>", new GUILayoutOption[] { GUILayout.Width(labelWidth) }))
|
||||||
{
|
{
|
||||||
WindowManager.InspectObject(obj, out bool _);
|
WindowManager.InspectObject(obj, out bool _);
|
||||||
}
|
}
|
||||||
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,20 +218,14 @@ namespace Explorer
|
|||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
GUILayout.Label("<b>Search:</b>", new GUILayoutOption[] { GUILayout.Width(75) });
|
GUILayout.Label("<b>Search:</b>", new GUILayoutOption[] { GUILayout.Width(75) });
|
||||||
m_search = GUILayout.TextField(m_search, null);
|
m_search = GUILayout.TextField(m_search, null);
|
||||||
GUILayout.Label("<b>Limit per page:</b>", new GUILayoutOption[] { GUILayout.Width(125) });
|
|
||||||
var limitString = m_limitPerPage.ToString();
|
|
||||||
limitString = GUILayout.TextField(limitString, new GUILayoutOption[] { GUILayout.Width(60) });
|
|
||||||
if (int.TryParse(limitString, out int i))
|
|
||||||
{
|
|
||||||
m_limitPerPage = i;
|
|
||||||
}
|
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
GUILayout.Label("<b>Filter:</b>", new GUILayoutOption[] { GUILayout.Width(75) });
|
GUILayout.Label("<b>Filter:</b>", new GUILayoutOption[] { GUILayout.Width(75) });
|
||||||
FilterToggle(MemberInfoType.All, "All");
|
FilterToggle(MemberTypes.All, "All");
|
||||||
FilterToggle(MemberInfoType.Property, "Properties");
|
FilterToggle(MemberTypes.Property, "Properties");
|
||||||
FilterToggle(MemberInfoType.Field, "Fields");
|
FilterToggle(MemberTypes.Field, "Fields");
|
||||||
|
FilterToggle(MemberTypes.Method, "Methods");
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
@ -240,102 +243,104 @@ namespace Explorer
|
|||||||
|
|
||||||
GUILayout.Space(10);
|
GUILayout.Space(10);
|
||||||
|
|
||||||
int count = m_cachedMemberFiltered.Length;
|
|
||||||
|
|
||||||
if (count > m_limitPerPage)
|
|
||||||
{
|
|
||||||
// prev/next page buttons
|
// prev/next page buttons
|
||||||
GUILayout.BeginHorizontal(null);
|
GUILayout.BeginHorizontal(null);
|
||||||
|
GUILayout.Label("<b>Limit per page:</b>", new GUILayoutOption[] { GUILayout.Width(125) });
|
||||||
|
var limitString = m_limitPerPage.ToString();
|
||||||
|
limitString = GUILayout.TextField(limitString, new GUILayoutOption[] { GUILayout.Width(60) });
|
||||||
|
if (int.TryParse(limitString, out int lim))
|
||||||
|
{
|
||||||
|
m_limitPerPage = lim;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = m_cachedMembersFiltered.Length;
|
||||||
|
if (count > m_limitPerPage)
|
||||||
|
{
|
||||||
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)m_limitPerPage)) - 1;
|
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)m_limitPerPage)) - 1;
|
||||||
if (GUILayout.Button("< Prev", null))
|
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
|
||||||
{
|
{
|
||||||
if (m_pageOffset > 0) m_pageOffset--;
|
if (m_pageOffset > 0) m_pageOffset--;
|
||||||
scroll = Vector2.zero;
|
scroll = Vector2.zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||||
GUILayout.Label($"Page {m_pageOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
|
GUILayout.Label($"Page {m_pageOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
|
||||||
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||||
|
|
||||||
if (GUILayout.Button("Next >", null))
|
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
|
||||||
{
|
{
|
||||||
if (m_pageOffset < maxOffset) m_pageOffset++;
|
if (m_pageOffset < maxOffset) m_pageOffset++;
|
||||||
scroll = Vector2.zero;
|
scroll = Vector2.zero;
|
||||||
}
|
}
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
}
|
}
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
// ====== BODY ======
|
||||||
|
|
||||||
scroll = GUILayout.BeginScrollView(scroll, GUI.skin.scrollView);
|
scroll = GUILayout.BeginScrollView(scroll, GUI.skin.scrollView);
|
||||||
|
|
||||||
GUILayout.Space(10);
|
GUILayout.Space(10);
|
||||||
|
|
||||||
DrawMembers(this.m_cachedMemberFiltered);
|
UIStyles.HorizontalLine(Color.grey);
|
||||||
|
|
||||||
|
GUILayout.BeginVertical(GUI.skin.box, null);
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
var members = this.m_cachedMembersFiltered;
|
||||||
|
int offsetIndex = (m_pageOffset * m_limitPerPage) + index;
|
||||||
|
|
||||||
|
if (offsetIndex >= count)
|
||||||
|
{
|
||||||
|
int maxOffset = (int)Mathf.Ceil((float)(m_cachedMembersFiltered.Length / (decimal)m_limitPerPage)) - 1;
|
||||||
|
if (m_pageOffset > maxOffset)
|
||||||
|
{
|
||||||
|
m_pageOffset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = offsetIndex; (j < offsetIndex + m_limitPerPage && j < members.Length); j++)
|
||||||
|
{
|
||||||
|
var holder = members[j];
|
||||||
|
|
||||||
|
GUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.Height(25) });
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
holder.Draw(rect, 180f);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.EndVertical();
|
||||||
GUILayout.EndScrollView();
|
GUILayout.EndScrollView();
|
||||||
|
|
||||||
m_rect = WindowManager.ResizeWindow(m_rect, windowID);
|
if (!WindowManager.TabView)
|
||||||
|
{
|
||||||
|
m_rect = ResizeDrag.ResizeWindow(rect, windowID);
|
||||||
|
|
||||||
GUILayout.EndArea();
|
GUILayout.EndArea();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Il2CppException e)
|
||||||
|
{
|
||||||
|
if (!e.Message.Contains("in a group with only"))
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
MelonLogger.LogWarning("Exception on window draw. Message: " + e.Message);
|
MelonLogger.LogWarning("Exception drawing ReflectionWindow: " + e.GetType() + ", " + e.Message);
|
||||||
DestroyWindow();
|
DestroyWindow();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawMembers(CacheObject[] members)
|
private void FilterToggle(MemberTypes mode, string label)
|
||||||
{
|
|
||||||
// todo pre-cache list based on current search, otherwise this doesnt work.
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
DrawMembersInternal("Properties", MemberInfoType.Property, members, ref i);
|
|
||||||
DrawMembersInternal("Fields", MemberInfoType.Field, members, ref i);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawMembersInternal(string title, MemberInfoType filter, CacheObject[] members, ref int index)
|
|
||||||
{
|
|
||||||
if (m_filter != filter && m_filter != MemberInfoType.All)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UIStyles.HorizontalLine(Color.grey);
|
|
||||||
|
|
||||||
GUILayout.Label($"<size=18><b><color=gold>{title}</color></b></size>", null);
|
|
||||||
|
|
||||||
int offset = (m_pageOffset * m_limitPerPage) + index;
|
|
||||||
|
|
||||||
if (offset >= m_cachedMemberFiltered.Length)
|
|
||||||
{
|
|
||||||
m_pageOffset = 0;
|
|
||||||
offset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = offset; j < offset + m_limitPerPage && j < members.Length; j++)
|
|
||||||
{
|
|
||||||
var holder = members[j];
|
|
||||||
|
|
||||||
if (holder.MemberInfoType != filter || !ShouldProcessMember(holder)) continue;
|
|
||||||
|
|
||||||
GUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.Height(25) });
|
|
||||||
try
|
|
||||||
{
|
|
||||||
holder.Draw(this.m_rect, 180f);
|
|
||||||
}
|
|
||||||
catch // (Exception e)
|
|
||||||
{
|
|
||||||
//MelonLogger.Log("Exception drawing member " + holder.MemberInfo.Name);
|
|
||||||
//MelonLogger.Log(e.GetType() + ", " + e.Message);
|
|
||||||
//MelonLogger.Log(e.StackTrace);
|
|
||||||
}
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
|
|
||||||
index++;
|
|
||||||
if (index >= m_limitPerPage) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FilterToggle(MemberInfoType mode, string label)
|
|
||||||
{
|
{
|
||||||
if (m_filter == mode)
|
if (m_filter == mode)
|
||||||
{
|
{
|
||||||
@ -348,6 +353,7 @@ namespace Explorer
|
|||||||
if (GUILayout.Button(label, new GUILayoutOption[] { GUILayout.Width(100) }))
|
if (GUILayout.Button(label, new GUILayoutOption[] { GUILayout.Width(100) }))
|
||||||
{
|
{
|
||||||
m_filter = mode;
|
m_filter = mode;
|
||||||
|
m_pageOffset = 0;
|
||||||
}
|
}
|
||||||
GUI.color = Color.white;
|
GUI.color = Color.white;
|
||||||
}
|
}
|
||||||
|
106
src/Windows/ResizeDrag.cs
Normal file
106
src/Windows/ResizeDrag.cs
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
using MelonLoader;
|
||||||
|
using UnhollowerBaseLib;
|
||||||
|
|
||||||
|
namespace Explorer
|
||||||
|
{
|
||||||
|
public class ResizeDrag
|
||||||
|
{
|
||||||
|
private static bool RESIZE_FAILED = false;
|
||||||
|
|
||||||
|
private static readonly GUIContent gcDrag = new GUIContent("<-- Drag to resize -->");
|
||||||
|
private static bool isResizing = false;
|
||||||
|
private static Rect m_currentResize;
|
||||||
|
private static int m_currentWindow;
|
||||||
|
|
||||||
|
public static Rect ResizeWindow(Rect _rect, int ID)
|
||||||
|
{
|
||||||
|
if (!RESIZE_FAILED)
|
||||||
|
{
|
||||||
|
var origRect = _rect;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GUILayout.BeginHorizontal(GUI.skin.box, null);
|
||||||
|
|
||||||
|
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
|
||||||
|
GUILayout.Button(gcDrag, GUI.skin.label, new GUILayoutOption[] { GUILayout.Height(15) });
|
||||||
|
|
||||||
|
var r = GUILayoutUtility.GetLastRect();
|
||||||
|
|
||||||
|
Vector2 mouse = GUIUtility.ScreenToGUIPoint(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y));
|
||||||
|
|
||||||
|
if (r.Contains(mouse) && Input.GetMouseButtonDown(0))
|
||||||
|
{
|
||||||
|
isResizing = true;
|
||||||
|
m_currentWindow = ID;
|
||||||
|
m_currentResize = new Rect(mouse.x, mouse.y, _rect.width, _rect.height);
|
||||||
|
}
|
||||||
|
else if (!Input.GetMouseButton(0))
|
||||||
|
{
|
||||||
|
isResizing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isResizing && ID == m_currentWindow)
|
||||||
|
{
|
||||||
|
_rect.width = Mathf.Max(100, m_currentResize.width + (mouse.x - m_currentResize.x));
|
||||||
|
_rect.height = Mathf.Max(100, m_currentResize.height + (mouse.y - m_currentResize.y));
|
||||||
|
_rect.xMax = Mathf.Min(Screen.width, _rect.xMax); // modifying xMax affects width, not x
|
||||||
|
_rect.yMax = Mathf.Min(Screen.height, _rect.yMax); // modifying yMax affects height, not y
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
}
|
||||||
|
catch (Il2CppException e) when (e.Message.StartsWith("System.ArgumentException"))
|
||||||
|
{
|
||||||
|
// suppress
|
||||||
|
return origRect;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
RESIZE_FAILED = true;
|
||||||
|
MelonLogger.Log("Exception on GuiResize: " + e.GetType() + ", " + e.Message);
|
||||||
|
return origRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GUILayout.BeginHorizontal(GUI.skin.box, null);
|
||||||
|
|
||||||
|
GUILayout.Label("Resize window:", new GUILayoutOption[] { GUILayout.Width(100) });
|
||||||
|
|
||||||
|
GUI.skin.label.alignment = TextAnchor.MiddleRight;
|
||||||
|
GUILayout.Label("<color=cyan>Width:</color>", new GUILayoutOption[] { GUILayout.Width(60) });
|
||||||
|
if (GUILayout.RepeatButton("-", new GUILayoutOption[] { GUILayout.Width(20) }))
|
||||||
|
{
|
||||||
|
_rect.width -= 5f;
|
||||||
|
}
|
||||||
|
if (GUILayout.RepeatButton("+", new GUILayoutOption[] { GUILayout.Width(20) }))
|
||||||
|
{
|
||||||
|
_rect.width += 5f;
|
||||||
|
}
|
||||||
|
GUILayout.Label("<color=cyan>Height:</color>", new GUILayoutOption[] { GUILayout.Width(60) });
|
||||||
|
if (GUILayout.RepeatButton("-", new GUILayoutOption[] { GUILayout.Width(20) }))
|
||||||
|
{
|
||||||
|
_rect.height -= 5f;
|
||||||
|
}
|
||||||
|
if (GUILayout.RepeatButton("+", new GUILayoutOption[] { GUILayout.Width(20) }))
|
||||||
|
{
|
||||||
|
_rect.height += 5f;
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
GUI.skin.label.alignment = TextAnchor.UpperLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _rect;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
116
src/Windows/TabViewWindow.cs
Normal file
116
src/Windows/TabViewWindow.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MelonLoader;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Explorer
|
||||||
|
{
|
||||||
|
public class TabViewWindow : UIWindow
|
||||||
|
{
|
||||||
|
public override string Title => $"Tabs ({WindowManager.Windows.Count})";
|
||||||
|
|
||||||
|
public static TabViewWindow Instance => m_instance ?? (m_instance = new TabViewWindow());
|
||||||
|
private static TabViewWindow m_instance;
|
||||||
|
|
||||||
|
private UIWindow m_targetWindow;
|
||||||
|
public int TargetTabID = 0;
|
||||||
|
|
||||||
|
public override bool IsTabViewWindow => true;
|
||||||
|
|
||||||
|
public TabViewWindow()
|
||||||
|
{
|
||||||
|
m_rect = new Rect(570, 0, 550, 700);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Init() { }
|
||||||
|
public override void Update()
|
||||||
|
{
|
||||||
|
while (TargetTabID >= WindowManager.Windows.Count)
|
||||||
|
{
|
||||||
|
TargetTabID--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TargetTabID == -1 && WindowManager.Windows.Count > 0)
|
||||||
|
{
|
||||||
|
TargetTabID = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TargetTabID >= 0)
|
||||||
|
{
|
||||||
|
m_targetWindow = WindowManager.Windows[TargetTabID];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_targetWindow = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_targetWindow?.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WindowFunction(int windowID)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GUI.DragWindow(new Rect(0, 0, m_rect.width - 90, 20));
|
||||||
|
if (GUI.Button(new Rect(m_rect.width - 90, 2, 80, 20), "<color=red>Close All</color>"))
|
||||||
|
{
|
||||||
|
foreach (var window in WindowManager.Windows)
|
||||||
|
{
|
||||||
|
window.DestroyWindow();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.BeginArea(new Rect(5, 25, m_rect.width - 10, m_rect.height - 35), GUI.skin.box);
|
||||||
|
|
||||||
|
GUILayout.BeginVertical(GUI.skin.box, null);
|
||||||
|
GUILayout.BeginHorizontal(null);
|
||||||
|
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||||
|
int tabPerRow = Mathf.FloorToInt((float)((decimal)m_rect.width / 238));
|
||||||
|
int rowCount = 0;
|
||||||
|
for (int i = 0; i < WindowManager.Windows.Count; i++)
|
||||||
|
{
|
||||||
|
if (rowCount >= tabPerRow)
|
||||||
|
{
|
||||||
|
rowCount = 0;
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
GUILayout.BeginHorizontal(null);
|
||||||
|
}
|
||||||
|
rowCount++;
|
||||||
|
|
||||||
|
bool focused = i == TargetTabID;
|
||||||
|
string color = focused ? "<color=lime>" : "<color=orange>";
|
||||||
|
GUI.color = focused ? Color.green : Color.white;
|
||||||
|
|
||||||
|
var window = WindowManager.Windows[i];
|
||||||
|
if (GUILayout.Button(color + window.Title + "</color>", new GUILayoutOption[] { GUILayout.Width(200) }))
|
||||||
|
{
|
||||||
|
TargetTabID = i;
|
||||||
|
}
|
||||||
|
if (GUILayout.Button("<color=red><b>X</b></color>", new GUILayoutOption[] { GUILayout.Width(22) }))
|
||||||
|
{
|
||||||
|
window.DestroyWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GUI.color = Color.white;
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
|
GUILayout.EndVertical();
|
||||||
|
GUI.skin.button.alignment = TextAnchor.MiddleCenter;
|
||||||
|
|
||||||
|
m_targetWindow.WindowFunction(m_targetWindow.windowID);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
m_rect = ResizeDrag.ResizeWindow(m_rect, windowID);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
GUILayout.EndArea();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,14 +7,12 @@ using MelonLoader;
|
|||||||
using UnhollowerBaseLib;
|
using UnhollowerBaseLib;
|
||||||
using UnhollowerRuntimeLib;
|
using UnhollowerRuntimeLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
|
||||||
using UnityEngine.EventSystems;
|
|
||||||
|
|
||||||
namespace Explorer
|
namespace Explorer
|
||||||
{
|
{
|
||||||
public abstract class UIWindow
|
public abstract class UIWindow
|
||||||
{
|
{
|
||||||
public abstract string Name { get; set; }
|
public abstract string Title { get; }
|
||||||
|
|
||||||
public object Target;
|
public object Target;
|
||||||
|
|
||||||
@ -23,6 +21,8 @@ namespace Explorer
|
|||||||
|
|
||||||
public Vector2 scroll = Vector2.zero;
|
public Vector2 scroll = Vector2.zero;
|
||||||
|
|
||||||
|
public virtual bool IsTabViewWindow => false;
|
||||||
|
|
||||||
public abstract void Init();
|
public abstract void Init();
|
||||||
public abstract void WindowFunction(int windowID);
|
public abstract void WindowFunction(int windowID);
|
||||||
public abstract void Update();
|
public abstract void Update();
|
||||||
@ -44,15 +44,7 @@ namespace Explorer
|
|||||||
|
|
||||||
public void DestroyWindow()
|
public void DestroyWindow()
|
||||||
{
|
{
|
||||||
try
|
WindowManager.DestroyWindow(this);
|
||||||
{
|
|
||||||
WindowManager.Windows.Remove(this);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
MelonLogger.Log("Exception removing Window from WindowManager.Windows list!");
|
|
||||||
MelonLogger.Log($"{e.GetType()} : {e.Message}\r\n{e.StackTrace}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnGUI()
|
public void OnGUI()
|
||||||
@ -62,13 +54,15 @@ namespace Explorer
|
|||||||
var origSkin = GUI.skin;
|
var origSkin = GUI.skin;
|
||||||
|
|
||||||
GUI.skin = UIStyles.WindowSkin;
|
GUI.skin = UIStyles.WindowSkin;
|
||||||
m_rect = GUI.Window(windowID, m_rect, (GUI.WindowFunction)WindowFunction, Name);
|
m_rect = GUI.Window(windowID, m_rect, (GUI.WindowFunction)WindowFunction, Title);
|
||||||
|
|
||||||
GUI.skin = origSkin;
|
GUI.skin = origSkin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Header()
|
public void Header()
|
||||||
|
{
|
||||||
|
if (!WindowManager.TabView)
|
||||||
{
|
{
|
||||||
GUI.DragWindow(new Rect(0, 0, m_rect.width - 90, 20));
|
GUI.DragWindow(new Rect(0, 0, m_rect.width - 90, 20));
|
||||||
|
|
||||||
@ -80,3 +74,4 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -16,30 +16,73 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
public static WindowManager Instance;
|
public static WindowManager Instance;
|
||||||
|
|
||||||
|
public static bool TabView = true;
|
||||||
|
|
||||||
public static List<UIWindow> Windows = new List<UIWindow>();
|
public static List<UIWindow> Windows = new List<UIWindow>();
|
||||||
public static int CurrentWindowID { get; set; } = 500000;
|
public static int CurrentWindowID { get; set; } = 500000;
|
||||||
private static Rect m_lastWindowRect;
|
private static Rect m_lastWindowRect;
|
||||||
|
|
||||||
|
private static readonly List<UIWindow> m_windowsToDestroy = new List<UIWindow>();
|
||||||
|
|
||||||
public WindowManager()
|
public WindowManager()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void DestroyWindow(UIWindow window)
|
||||||
|
{
|
||||||
|
m_windowsToDestroy.Add(window);
|
||||||
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
foreach (var window in Windows)
|
if (m_windowsToDestroy.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var window in m_windowsToDestroy)
|
||||||
|
{
|
||||||
|
if (Windows.Contains(window))
|
||||||
|
{
|
||||||
|
Windows.Remove(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_windowsToDestroy.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TabView)
|
||||||
|
{
|
||||||
|
TabViewWindow.Instance.Update();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Windows.Count; i++)
|
||||||
|
{
|
||||||
|
var window = Windows[i];
|
||||||
|
if (window != null)
|
||||||
{
|
{
|
||||||
window.Update();
|
window.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void OnGUI()
|
public void OnGUI()
|
||||||
|
{
|
||||||
|
if (TabView)
|
||||||
|
{
|
||||||
|
if (Windows.Count > 0)
|
||||||
|
{
|
||||||
|
TabViewWindow.Instance.OnGUI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
foreach (var window in Windows)
|
foreach (var window in Windows)
|
||||||
{
|
{
|
||||||
window.OnGUI();
|
window.OnGUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ========= Public Helpers =========
|
// ========= Public Helpers =========
|
||||||
|
|
||||||
@ -102,12 +145,24 @@ namespace Explorer
|
|||||||
{
|
{
|
||||||
createdNew = false;
|
createdNew = false;
|
||||||
|
|
||||||
|
UnityEngine.Object uObj = null;
|
||||||
|
if (obj is UnityEngine.Object)
|
||||||
|
{
|
||||||
|
uObj = obj as UnityEngine.Object;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var window in Windows)
|
foreach (var window in Windows)
|
||||||
{
|
{
|
||||||
if (ReferenceEquals(obj, window.Target))
|
bool equals = ReferenceEquals(obj, window.Target);
|
||||||
|
|
||||||
|
if (!equals && uObj != null && window.Target is UnityEngine.Object uTarget)
|
||||||
{
|
{
|
||||||
GUI.BringWindowToFront(window.windowID);
|
equals = uObj.m_CachedPtr == uTarget.m_CachedPtr;
|
||||||
GUI.FocusWindow(window.windowID);
|
}
|
||||||
|
|
||||||
|
if (equals)
|
||||||
|
{
|
||||||
|
FocusWindow(window);
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,10 +178,23 @@ namespace Explorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void FocusWindow(UIWindow window)
|
||||||
|
{
|
||||||
|
if (!TabView)
|
||||||
|
{
|
||||||
|
GUI.BringWindowToFront(window.windowID);
|
||||||
|
GUI.FocusWindow(window.windowID);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TabViewWindow.Instance.TargetTabID = Windows.IndexOf(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static UIWindow InspectGameObject(GameObject obj)
|
private static UIWindow InspectGameObject(GameObject obj)
|
||||||
{
|
{
|
||||||
var new_window = UIWindow.CreateWindow<GameObjectWindow>(obj);
|
var new_window = UIWindow.CreateWindow<GameObjectWindow>(obj);
|
||||||
GUI.FocusWindow(new_window.windowID);
|
FocusWindow(new_window);
|
||||||
|
|
||||||
return new_window;
|
return new_window;
|
||||||
}
|
}
|
||||||
@ -134,56 +202,9 @@ namespace Explorer
|
|||||||
public static UIWindow InspectReflection(object obj)
|
public static UIWindow InspectReflection(object obj)
|
||||||
{
|
{
|
||||||
var new_window = UIWindow.CreateWindow<ReflectionWindow>(obj);
|
var new_window = UIWindow.CreateWindow<ReflectionWindow>(obj);
|
||||||
GUI.FocusWindow(new_window.windowID);
|
FocusWindow(new_window);
|
||||||
|
|
||||||
return new_window;
|
return new_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============= Resize Window Helper ============
|
|
||||||
|
|
||||||
// static readonly GUIContent gcDrag = new GUIContent("<->", "drag to resize");
|
|
||||||
private static readonly GUIContent gcDrag = new GUIContent("<->");
|
|
||||||
private static bool isResizing = false;
|
|
||||||
private static Rect m_currentResize;
|
|
||||||
private static int m_currentWindow;
|
|
||||||
|
|
||||||
public static Rect ResizeWindow(Rect _rect, int ID)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
GUILayout.BeginHorizontal(null);
|
|
||||||
GUILayout.Space(_rect.width - 35);
|
|
||||||
|
|
||||||
GUILayout.Button(gcDrag, GUI.skin.label, new GUILayoutOption[] { GUILayout.Width(25), GUILayout.Height(25) });
|
|
||||||
|
|
||||||
var r = GUILayoutUtility.GetLastRect();
|
|
||||||
|
|
||||||
Vector2 mouse = GUIUtility.ScreenToGUIPoint(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y));
|
|
||||||
|
|
||||||
if (r.Contains(mouse) && Input.GetMouseButtonDown(0))
|
|
||||||
{
|
|
||||||
isResizing = true;
|
|
||||||
m_currentWindow = ID;
|
|
||||||
m_currentResize = new Rect(mouse.x, mouse.y, _rect.width, _rect.height);
|
|
||||||
}
|
|
||||||
else if (!Input.GetMouseButton(0))
|
|
||||||
{
|
|
||||||
isResizing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isResizing && ID == m_currentWindow)
|
|
||||||
{
|
|
||||||
_rect.width = Mathf.Max(100, m_currentResize.width + (mouse.x - m_currentResize.x));
|
|
||||||
_rect.height = Mathf.Max(100, m_currentResize.height + (mouse.y - m_currentResize.y));
|
|
||||||
_rect.xMax = Mathf.Min(Screen.width, _rect.xMax); // modifying xMax affects width, not x
|
|
||||||
_rect.yMax = Mathf.Min(Screen.height, _rect.yMax); // modifying yMax affects height, not y
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
|
|
||||||
return _rect;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user