mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-01-09 10:38:59 +08:00
Made instance inspector helper (owner gameobject/name), force loading unhollowed Assembly-CSharp on game start
This commit is contained in:
parent
e77e4cce07
commit
97dbecaa2a
@ -8,13 +8,14 @@ using UnityExplorer.Inspectors;
|
||||
using System.IO;
|
||||
using UnityExplorer.Unstrip;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityExplorer.Helpers;
|
||||
|
||||
namespace UnityExplorer
|
||||
{
|
||||
public class ExplorerCore
|
||||
{
|
||||
public const string NAME = "UnityExplorer";
|
||||
public const string VERSION = "3.0.1";
|
||||
public const string VERSION = "3.0.2";
|
||||
public const string AUTHOR = "Sinai";
|
||||
public const string GUID = "com.sinai.unityexplorer";
|
||||
public const string EXPLORER_FOLDER = @"Mods\UnityExplorer";
|
||||
@ -41,6 +42,10 @@ namespace UnityExplorer
|
||||
|
||||
Instance = this;
|
||||
|
||||
#if CPP
|
||||
ReflectionHelpers.TryLoadGameModules();
|
||||
#endif
|
||||
|
||||
if (!Directory.Exists(EXPLORER_FOLDER))
|
||||
Directory.CreateDirectory(EXPLORER_FOLDER);
|
||||
|
||||
|
@ -105,21 +105,19 @@ namespace UnityExplorer.Helpers
|
||||
return getType;
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Type, IntPtr> ClassPointers = new Dictionary<Type, IntPtr>();
|
||||
private static readonly Dictionary<Type, IntPtr> CppClassPointers = new Dictionary<Type, IntPtr>();
|
||||
|
||||
public static object Il2CppCast(this object obj, Type castTo)
|
||||
{
|
||||
if (!(obj is Il2CppSystem.Object ilObj))
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (!Il2CppTypeNotNull(castTo, out IntPtr castToPtr))
|
||||
return obj;
|
||||
|
||||
IntPtr classPtr = il2cpp_object_get_class(ilObj.Pointer);
|
||||
IntPtr castFromPtr = il2cpp_object_get_class(ilObj.Pointer);
|
||||
|
||||
if (!il2cpp_class_is_assignable_from(castToPtr, classPtr))
|
||||
if (!il2cpp_class_is_assignable_from(castToPtr, castFromPtr))
|
||||
return obj;
|
||||
|
||||
if (RuntimeSpecificsStore.IsInjected(castToPtr))
|
||||
@ -128,24 +126,21 @@ namespace UnityExplorer.Helpers
|
||||
return Activator.CreateInstance(castTo, ilObj.Pointer);
|
||||
}
|
||||
|
||||
public static bool Il2CppTypeNotNull(Type type)
|
||||
{
|
||||
return Il2CppTypeNotNull(type, out _);
|
||||
}
|
||||
public static bool Il2CppTypeNotNull(Type type) => Il2CppTypeNotNull(type, out _);
|
||||
|
||||
public static bool Il2CppTypeNotNull(Type type, out IntPtr il2cppPtr)
|
||||
{
|
||||
if (!ClassPointers.ContainsKey(type))
|
||||
if (!CppClassPointers.ContainsKey(type))
|
||||
{
|
||||
il2cppPtr = (IntPtr)typeof(Il2CppClassPointerStore<>)
|
||||
.MakeGenericType(new Type[] { type })
|
||||
.GetField("NativeClassPtr", BF.Public | BF.Static)
|
||||
.GetValue(null);
|
||||
|
||||
ClassPointers.Add(type, il2cppPtr);
|
||||
CppClassPointers.Add(type, il2cppPtr);
|
||||
}
|
||||
else
|
||||
il2cppPtr = ClassPointers[type];
|
||||
il2cppPtr = CppClassPointers[type];
|
||||
|
||||
return il2cppPtr != IntPtr.Zero;
|
||||
}
|
||||
@ -181,31 +176,42 @@ namespace UnityExplorer.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
#if CPP
|
||||
internal static void TryLoadGameModules()
|
||||
{
|
||||
LoadModule("Assembly-CSharp");
|
||||
LoadModule("Assembly-CSharp-firstpass");
|
||||
}
|
||||
|
||||
public static bool LoadModule(string module)
|
||||
{
|
||||
#if CPP
|
||||
#if ML
|
||||
string path = $@"MelonLoader\Managed\{module}.dll";
|
||||
var path = $@"MelonLoader\Managed\{module}.dll";
|
||||
#else
|
||||
var path = $@"BepInEx\unhollowed\{module}.dll";
|
||||
#endif
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
|
||||
return LoadModuleInternal(path);
|
||||
}
|
||||
|
||||
internal static bool LoadModuleInternal(string fullPath)
|
||||
{
|
||||
if (!File.Exists(fullPath))
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Assembly.Load(File.ReadAllBytes(path));
|
||||
Assembly.Load(File.ReadAllBytes(fullPath));
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExplorerCore.Log(e.GetType() + ", " + e.Message);
|
||||
Console.WriteLine(e.GetType() + ", " + e.Message);
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
public static bool IsEnumerable(Type t)
|
||||
{
|
||||
|
@ -12,8 +12,17 @@ namespace UnityExplorer.Input
|
||||
{
|
||||
private static IHandleInput m_inputModule;
|
||||
|
||||
public static Vector3 MousePosition => m_inputModule.MousePosition;
|
||||
|
||||
public static bool GetKeyDown(KeyCode key) => m_inputModule.GetKeyDown(key);
|
||||
public static bool GetKey(KeyCode key) => m_inputModule.GetKey(key);
|
||||
|
||||
public static bool GetMouseButtonDown(int btn) => m_inputModule.GetMouseButtonDown(btn);
|
||||
public static bool GetMouseButton(int btn) => m_inputModule.GetMouseButton(btn);
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
#if CPP
|
||||
if (InputSystem.TKeyboard != null || (ReflectionHelpers.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
|
||||
{
|
||||
m_inputModule = new InputSystem();
|
||||
@ -22,6 +31,7 @@ namespace UnityExplorer.Input
|
||||
{
|
||||
m_inputModule = new LegacyInput();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_inputModule == null)
|
||||
{
|
||||
@ -29,13 +39,5 @@ namespace UnityExplorer.Input
|
||||
m_inputModule = new NoInput();
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 MousePosition => m_inputModule.MousePosition;
|
||||
|
||||
public static bool GetKeyDown(KeyCode key) => m_inputModule.GetKeyDown(key);
|
||||
public static bool GetKey(KeyCode key) => m_inputModule.GetKey(key);
|
||||
|
||||
public static bool GetMouseButtonDown(int btn) => m_inputModule.GetMouseButtonDown(btn);
|
||||
public static bool GetMouseButton(int btn) => m_inputModule.GetMouseButton(btn);
|
||||
}
|
||||
}
|
@ -45,19 +45,95 @@ namespace UnityExplorer.Inspectors.Reflection
|
||||
|
||||
public void ConstructInstanceHelpers()
|
||||
{
|
||||
if (!typeof(Component).IsAssignableFrom(m_targetType) && !typeof(UnityEngine.Object).IsAssignableFrom(m_targetType))
|
||||
return;
|
||||
|
||||
var rowObj = UIFactory.CreateHorizontalGroup(Content, new Color(0.1f, 0.1f, 0.1f));
|
||||
var rowGroup = rowObj.GetComponent<HorizontalLayoutGroup>();
|
||||
rowGroup.childForceExpandWidth = true;
|
||||
rowGroup.childControlWidth = true;
|
||||
rowGroup.spacing = 5;
|
||||
rowGroup.padding.top = 2;
|
||||
rowGroup.padding.bottom = 2;
|
||||
rowGroup.padding.right = 2;
|
||||
rowGroup.padding.left = 2;
|
||||
var rowLayout = rowObj.AddComponent<LayoutElement>();
|
||||
rowLayout.minHeight = 25;
|
||||
rowLayout.flexibleWidth = 5000;
|
||||
|
||||
if (typeof(Component).IsAssignableFrom(m_targetType))
|
||||
{
|
||||
ConstructCompHelper(rowObj);
|
||||
}
|
||||
|
||||
ConstructUObjHelper(rowObj);
|
||||
|
||||
// WIP
|
||||
|
||||
//if (m_targetType == typeof(Texture2D))
|
||||
// ConstructTextureHelper();
|
||||
}
|
||||
|
||||
// todo other helpers
|
||||
internal void ConstructCompHelper(GameObject rowObj)
|
||||
{
|
||||
var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||
var labelLayout = labelObj.AddComponent<LayoutElement>();
|
||||
labelLayout.minWidth = 90;
|
||||
labelLayout.minHeight = 25;
|
||||
labelLayout.flexibleWidth = 0;
|
||||
var labelText = labelObj.GetComponent<Text>();
|
||||
labelText.text = "GameObject:";
|
||||
|
||||
//if (typeof(Component).IsAssignableFrom(m_targetType))
|
||||
//{
|
||||
//}
|
||||
//else if (typeof(UnityEngine.Object).IsAssignableFrom(m_targetType))
|
||||
//{
|
||||
//}
|
||||
#if MONO
|
||||
var comp = Target as Component;
|
||||
#else
|
||||
var comp = (Target as Il2CppSystem.Object).TryCast<Component>();
|
||||
#endif
|
||||
|
||||
var goBtnObj = UIFactory.CreateButton(rowObj, new Color(0.2f, 0.5f, 0.2f));
|
||||
var goBtnLayout = goBtnObj.AddComponent<LayoutElement>();
|
||||
goBtnLayout.minHeight = 25;
|
||||
goBtnLayout.minWidth = 200;
|
||||
goBtnLayout.flexibleWidth = 0;
|
||||
var text = goBtnObj.GetComponentInChildren<Text>();
|
||||
text.text = comp.name;
|
||||
var btn = goBtnObj.GetComponent<Button>();
|
||||
btn.onClick.AddListener(() => { InspectorManager.Instance.Inspect(comp.gameObject); });
|
||||
}
|
||||
|
||||
internal void ConstructUObjHelper(GameObject rowObj)
|
||||
{
|
||||
var labelObj = UIFactory.CreateLabel(rowObj, TextAnchor.MiddleLeft);
|
||||
var labelLayout = labelObj.AddComponent<LayoutElement>();
|
||||
labelLayout.minWidth = 60;
|
||||
labelLayout.minHeight = 25;
|
||||
labelLayout.flexibleWidth = 0;
|
||||
var labelText = labelObj.GetComponent<Text>();
|
||||
labelText.text = "Name:";
|
||||
|
||||
#if MONO
|
||||
var uObj = Target as UnityEngine.Object;
|
||||
#else
|
||||
var uObj = (Target as Il2CppSystem.Object).TryCast<UnityEngine.Object>();
|
||||
#endif
|
||||
|
||||
var inputObj = UIFactory.CreateInputField(rowObj, 14, 3, 1);
|
||||
var inputLayout = inputObj.AddComponent<LayoutElement>();
|
||||
inputLayout.minHeight = 25;
|
||||
inputLayout.flexibleWidth = 2000;
|
||||
var inputField = inputObj.GetComponent<InputField>();
|
||||
inputField.readOnly = true;
|
||||
inputField.text = uObj.name;
|
||||
|
||||
//var goBtnObj = UIFactory.CreateButton(rowObj, new Color(0.2f, 0.5f, 0.2f));
|
||||
//var goBtnLayout = goBtnObj.AddComponent<LayoutElement>();
|
||||
//goBtnLayout.minHeight = 25;
|
||||
//goBtnLayout.minWidth = 200;
|
||||
//goBtnLayout.flexibleWidth = 0;
|
||||
//var text = goBtnObj.GetComponentInChildren<Text>();
|
||||
//text.text = comp.name;
|
||||
//var btn = goBtnObj.GetComponent<Button>();
|
||||
//btn.onClick.AddListener(() => { InspectorManager.Instance.Inspect(comp.gameObject); });
|
||||
}
|
||||
|
||||
//internal bool showingTextureHelper;
|
||||
|
@ -179,7 +179,7 @@ namespace UnityExplorer.Inspectors
|
||||
var pi = member as PropertyInfo;
|
||||
var fi = member as FieldInfo;
|
||||
|
||||
if (IsBlacklisted(sig) || mi != null && IsBlacklisted(mi))
|
||||
if (IsBlacklisted(sig) || (mi != null && IsBlacklisted(mi)))
|
||||
continue;
|
||||
|
||||
var args = mi?.GetParameters() ?? pi?.GetIndexParameters();
|
||||
@ -581,7 +581,7 @@ namespace UnityExplorer.Inspectors
|
||||
|
||||
internal void ConstructMemberList()
|
||||
{
|
||||
var scrollobj = UIFactory.CreateScrollView(Content, out m_scrollContent, out m_sliderScroller, new Color(0.08f, 0.08f, 0.08f));
|
||||
var scrollobj = UIFactory.CreateScrollView(Content, out m_scrollContent, out m_sliderScroller, new Color(0.05f, 0.05f, 0.05f));
|
||||
|
||||
m_scrollContentRect = m_scrollContent.GetComponent<RectTransform>();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user