mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00

- Added ability to cycle through "pages" with lists/arrays and with search results. Also reduced default array display limit to 20 elements, since we can now just cycle through pages. - Some backend restructuring / cleanups
127 lines
4.3 KiB
C#
127 lines
4.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using MelonLoader;
|
|
using UnhollowerBaseLib;
|
|
|
|
namespace Explorer
|
|
{
|
|
public class PropertyInfoHolder : MemberInfoHolder
|
|
{
|
|
public PropertyInfo propInfo;
|
|
public object m_value;
|
|
|
|
public PropertyInfoHolder(Type _type, PropertyInfo _propInfo)
|
|
{
|
|
classType = _type;
|
|
propInfo = _propInfo;
|
|
}
|
|
|
|
public override void Draw(ReflectionWindow window)
|
|
{
|
|
UIStyles.DrawMember(ref m_value, ref this.IsExpanded, ref this.arrayOffset, this.propInfo, window.m_rect, window.m_object, SetValue);
|
|
}
|
|
|
|
public override void UpdateValue(object obj)
|
|
{
|
|
try
|
|
{
|
|
if (obj is Il2CppSystem.Object ilObject)
|
|
{
|
|
var declaringType = this.propInfo.DeclaringType;
|
|
if (declaringType == typeof(Il2CppObjectBase))
|
|
{
|
|
m_value = ilObject.Pointer;
|
|
}
|
|
else
|
|
{
|
|
var cast = CppExplorer.Il2CppCast(obj, declaringType);
|
|
m_value = this.propInfo.GetValue(cast, null);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_value = this.propInfo.GetValue(obj, null);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
MelonLogger.Log("Exception on PropertyInfoHolder.UpdateValue, Name: " + this.propInfo.Name);
|
|
MelonLogger.Log(e.GetType() + ", " + e.Message);
|
|
|
|
var inner = e.InnerException;
|
|
while (inner != null)
|
|
{
|
|
MelonLogger.Log("inner: " + inner.GetType() + ", " + inner.Message);
|
|
inner = inner.InnerException;
|
|
}
|
|
|
|
m_value = null;
|
|
}
|
|
}
|
|
|
|
public override void SetValue(object obj)
|
|
{
|
|
try
|
|
{
|
|
if (propInfo.PropertyType.IsEnum)
|
|
{
|
|
if (System.Enum.Parse(propInfo.PropertyType, m_value.ToString()) is object enumValue && enumValue != null)
|
|
{
|
|
m_value = enumValue;
|
|
}
|
|
}
|
|
else if (propInfo.PropertyType.IsPrimitive)
|
|
{
|
|
if (propInfo.PropertyType == typeof(float))
|
|
{
|
|
if (float.TryParse(m_value.ToString(), out float f))
|
|
{
|
|
m_value = f;
|
|
}
|
|
else
|
|
{
|
|
MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a float!");
|
|
}
|
|
}
|
|
else if (propInfo.PropertyType == typeof(double))
|
|
{
|
|
if (double.TryParse(m_value.ToString(), out double d))
|
|
{
|
|
m_value = d;
|
|
}
|
|
else
|
|
{
|
|
MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a double!");
|
|
}
|
|
}
|
|
else if (propInfo.PropertyType != typeof(bool))
|
|
{
|
|
if (int.TryParse(m_value.ToString(), out int i))
|
|
{
|
|
m_value = i;
|
|
}
|
|
else
|
|
{
|
|
MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to an integer! type: " + propInfo.PropertyType);
|
|
}
|
|
}
|
|
}
|
|
|
|
var declaring = propInfo.DeclaringType;
|
|
var cast = CppExplorer.Il2CppCast(obj, declaring);
|
|
|
|
propInfo.SetValue(propInfo.GetAccessors()[0].IsStatic ? null : cast, m_value, null);
|
|
}
|
|
catch
|
|
{
|
|
//MelonLogger.Log("Exception trying to set property " + this.propInfo.Name);
|
|
}
|
|
}
|
|
}
|
|
}
|