- Project structure cleanup
- Code refactoring
- Adding some extension methods for cleaner looking code
- Performance improvements on Object Reflection window
This commit is contained in:
sinaioutlander 2020-08-18 17:38:09 +10:00
parent 153ad2268b
commit 72c222d59a
7 changed files with 65 additions and 36 deletions

View File

@ -137,6 +137,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CppExplorer.cs" /> <Compile Include="CppExplorer.cs" />
<Compile Include="Extensions\ReflectionExtensions.cs" />
<Compile Include="Extensions\UnityExtensions.cs" />
<Compile Include="Helpers\ReflectionHelpers.cs" /> <Compile Include="Helpers\ReflectionHelpers.cs" />
<Compile Include="Helpers\UIHelpers.cs" /> <Compile Include="Helpers\UIHelpers.cs" />
<Compile Include="Helpers\UnityHelpers.cs" /> <Compile Include="Helpers\UnityHelpers.cs" />

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Explorer
{
public static class ReflectionExtensions
{
public static object Il2CppCast(this object obj, Type castTo)
{
return ReflectionHelpers.Il2CppCast(obj, castTo);
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Explorer
{
public static class UnityExtensions
{
public static string GetGameObjectPath(this Transform _transform)
{
return GetGameObjectPath(_transform, true);
}
public static string GetGameObjectPath(this Transform _transform, bool _includeThisName)
{
string path = _includeThisName ? ("/" + _transform.name) : "";
GameObject gameObject = _transform.gameObject;
while (gameObject.transform.parent != null)
{
gameObject = gameObject.transform.parent.gameObject;
path = "/" + gameObject.name + path;
}
return path;
}
}
}

View File

@ -7,7 +7,7 @@ using UnityEngine;
namespace Explorer namespace Explorer
{ {
public static class UnityHelpers public class UnityHelpers
{ {
private static Camera m_mainCamera; private static Camera m_mainCamera;
@ -30,22 +30,5 @@ namespace Explorer
return UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; return UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
} }
} }
public static string GetGameObjectPath(this Transform _transform)
{
return GetGameObjectPath(_transform, true);
}
public static string GetGameObjectPath(this Transform _transform, bool _includeThisName)
{
string path = _includeThisName ? ("/" + _transform.name) : "";
GameObject gameObject = _transform.gameObject;
while (gameObject.transform.parent != null)
{
gameObject = gameObject.transform.parent.gameObject;
path = "/" + gameObject.name + path;
}
return path;
}
} }
} }

View File

@ -28,7 +28,8 @@ namespace Explorer
{ {
var declaringType = this.fieldInfo.DeclaringType; var declaringType = this.fieldInfo.DeclaringType;
var cast = ReflectionHelpers.Il2CppCast(obj, declaringType); //var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
var cast = obj.Il2CppCast(declaringType);
m_value = this.fieldInfo.GetValue(fieldInfo.IsStatic ? null : cast); m_value = this.fieldInfo.GetValue(fieldInfo.IsStatic ? null : cast);
} }
else else
@ -103,7 +104,8 @@ namespace Explorer
{ {
var declaringType = this.fieldInfo.DeclaringType; var declaringType = this.fieldInfo.DeclaringType;
var cast = ReflectionHelpers.Il2CppCast(obj, declaringType); //var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
var cast = obj.Il2CppCast(declaringType);
fieldInfo.SetValue(fieldInfo.IsStatic ? null : cast, m_value); fieldInfo.SetValue(fieldInfo.IsStatic ? null : cast, m_value);
} }
else else

View File

@ -40,7 +40,8 @@ namespace Explorer
} }
else else
{ {
var cast = ReflectionHelpers.Il2CppCast(obj, declaringType); //var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
var cast = obj.Il2CppCast(declaringType);
m_value = this.propInfo.GetValue(this.propInfo.GetAccessors()[0].IsStatic ? null : cast, null); m_value = this.propInfo.GetValue(this.propInfo.GetAccessors()[0].IsStatic ? null : cast, null);
} }
} }
@ -49,19 +50,19 @@ namespace Explorer
m_value = this.propInfo.GetValue(obj, null); m_value = this.propInfo.GetValue(obj, null);
} }
} }
catch (Exception e) catch //(Exception e)
{ {
MelonLogger.Log("Exception on PropertyInfoHolder.UpdateValue, Name: " + this.propInfo.Name); //MelonLogger.Log("Exception on PropertyInfoHolder.UpdateValue, Name: " + this.propInfo.Name);
MelonLogger.Log(e.GetType() + ", " + e.Message); //MelonLogger.Log(e.GetType() + ", " + e.Message);
var inner = e.InnerException; //var inner = e.InnerException;
while (inner != null) //while (inner != null)
{ //{
MelonLogger.Log("inner: " + inner.GetType() + ", " + inner.Message); // MelonLogger.Log("inner: " + inner.GetType() + ", " + inner.Message);
inner = inner.InnerException; // inner = inner.InnerException;
} //}
m_value = null; //m_value = null;
} }
} }
@ -113,9 +114,7 @@ namespace Explorer
} }
} }
var declaring = propInfo.DeclaringType; var cast = obj.Il2CppCast(propInfo.DeclaringType);
var cast = ReflectionHelpers.Il2CppCast(obj, declaring);
propInfo.SetValue(propInfo.GetAccessors()[0].IsStatic ? null : cast, m_value, null); propInfo.SetValue(propInfo.GetAccessors()[0].IsStatic ? null : cast, m_value, null);
} }
catch catch

View File

@ -48,8 +48,6 @@ namespace Explorer
CacheFields(types); CacheFields(types);
CacheProperties(types); CacheProperties(types);
MelonLogger.Log("Cached properties: " + m_PropertyInfos.Length);
UpdateValues(true); UpdateValues(true);
} }