Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 72c222d

Browse files
committed
1.3.5
- Project structure cleanup - Code refactoring - Adding some extension methods for cleaner looking code - Performance improvements on Object Reflection window
1 parent 153ad22 commit 72c222d

File tree

7 files changed

+65
-36
lines changed

7 files changed

+65
-36
lines changed

src/CppExplorer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
</ItemGroup>
138138
<ItemGroup>
139139
<Compile Include="CppExplorer.cs" />
140+
<Compile Include="Extensions\ReflectionExtensions.cs" />
141+
<Compile Include="Extensions\UnityExtensions.cs" />
140142
<Compile Include="Helpers\ReflectionHelpers.cs" />
141143
<Compile Include="Helpers\UIHelpers.cs" />
142144
<Compile Include="Helpers\UnityHelpers.cs" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Explorer
8+
{
9+
public static class ReflectionExtensions
10+
{
11+
public static object Il2CppCast(this object obj, Type castTo)
12+
{
13+
return ReflectionHelpers.Il2CppCast(obj, castTo);
14+
}
15+
}
16+
}

src/Extensions/UnityExtensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using UnityEngine;
7+
8+
namespace Explorer
9+
{
10+
public static class UnityExtensions
11+
{
12+
public static string GetGameObjectPath(this Transform _transform)
13+
{
14+
return GetGameObjectPath(_transform, true);
15+
}
16+
17+
public static string GetGameObjectPath(this Transform _transform, bool _includeThisName)
18+
{
19+
string path = _includeThisName ? ("/" + _transform.name) : "";
20+
GameObject gameObject = _transform.gameObject;
21+
while (gameObject.transform.parent != null)
22+
{
23+
gameObject = gameObject.transform.parent.gameObject;
24+
path = "/" + gameObject.name + path;
25+
}
26+
return path;
27+
}
28+
}
29+
}

src/Helpers/UnityHelpers.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Explorer
99
{
10-
public static class UnityHelpers
10+
public class UnityHelpers
1111
{
1212
private static Camera m_mainCamera;
1313

@@ -30,22 +30,5 @@ public static string ActiveSceneName
3030
return UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
3131
}
3232
}
33-
34-
public static string GetGameObjectPath(this Transform _transform)
35-
{
36-
return GetGameObjectPath(_transform, true);
37-
}
38-
39-
public static string GetGameObjectPath(this Transform _transform, bool _includeThisName)
40-
{
41-
string path = _includeThisName ? ("/" + _transform.name) : "";
42-
GameObject gameObject = _transform.gameObject;
43-
while (gameObject.transform.parent != null)
44-
{
45-
gameObject = gameObject.transform.parent.gameObject;
46-
path = "/" + gameObject.name + path;
47-
}
48-
return path;
49-
}
5033
}
5134
}

src/Windows/Reflection/FieldInfoHolder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public override void UpdateValue(object obj)
2828
{
2929
var declaringType = this.fieldInfo.DeclaringType;
3030

31-
var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
31+
//var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
32+
var cast = obj.Il2CppCast(declaringType);
3233
m_value = this.fieldInfo.GetValue(fieldInfo.IsStatic ? null : cast);
3334
}
3435
else
@@ -103,7 +104,8 @@ public override void SetValue(object obj)
103104
{
104105
var declaringType = this.fieldInfo.DeclaringType;
105106

106-
var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
107+
//var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
108+
var cast = obj.Il2CppCast(declaringType);
107109
fieldInfo.SetValue(fieldInfo.IsStatic ? null : cast, m_value);
108110
}
109111
else

src/Windows/Reflection/PropertyInfoHolder.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public override void UpdateValue(object obj)
4040
}
4141
else
4242
{
43-
var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
43+
//var cast = ReflectionHelpers.Il2CppCast(obj, declaringType);
44+
var cast = obj.Il2CppCast(declaringType);
4445
m_value = this.propInfo.GetValue(this.propInfo.GetAccessors()[0].IsStatic ? null : cast, null);
4546
}
4647
}
@@ -49,19 +50,19 @@ public override void UpdateValue(object obj)
4950
m_value = this.propInfo.GetValue(obj, null);
5051
}
5152
}
52-
catch (Exception e)
53+
catch //(Exception e)
5354
{
54-
MelonLogger.Log("Exception on PropertyInfoHolder.UpdateValue, Name: " + this.propInfo.Name);
55-
MelonLogger.Log(e.GetType() + ", " + e.Message);
55+
//MelonLogger.Log("Exception on PropertyInfoHolder.UpdateValue, Name: " + this.propInfo.Name);
56+
//MelonLogger.Log(e.GetType() + ", " + e.Message);
5657

57-
var inner = e.InnerException;
58-
while (inner != null)
59-
{
60-
MelonLogger.Log("inner: " + inner.GetType() + ", " + inner.Message);
61-
inner = inner.InnerException;
62-
}
58+
//var inner = e.InnerException;
59+
//while (inner != null)
60+
//{
61+
// MelonLogger.Log("inner: " + inner.GetType() + ", " + inner.Message);
62+
// inner = inner.InnerException;
63+
//}
6364

64-
m_value = null;
65+
//m_value = null;
6566
}
6667
}
6768

@@ -113,9 +114,7 @@ public override void SetValue(object obj)
113114
}
114115
}
115116

116-
var declaring = propInfo.DeclaringType;
117-
var cast = ReflectionHelpers.Il2CppCast(obj, declaring);
118-
117+
var cast = obj.Il2CppCast(propInfo.DeclaringType);
119118
propInfo.SetValue(propInfo.GetAccessors()[0].IsStatic ? null : cast, m_value, null);
120119
}
121120
catch

src/Windows/ReflectionWindow.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public override void Init()
4848
CacheFields(types);
4949
CacheProperties(types);
5050

51-
MelonLogger.Log("Cached properties: " + m_PropertyInfos.Length);
52-
5351
UpdateValues(true);
5452
}
5553

0 commit comments

Comments
 (0)