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

Commit a2677e2

Browse files
committed
1.3.1
- 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
1 parent 13c2d6b commit a2677e2

30 files changed

+931
-711
lines changed

src/CppExplorer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class CppExplorer : MelonMod
1616

1717
public const string ID = "com.sinai.cppexplorer";
1818
public const string NAME = "IL2CPP Runtime Explorer";
19-
public const string VERSION = "1.3.0";
19+
public const string VERSION = "1.3.1";
2020
public const string AUTHOR = "Sinai";
2121

2222
// fields
@@ -28,7 +28,7 @@ public class CppExplorer : MelonMod
2828
// props
2929

3030
public static bool ShowMenu { get; set; } = false;
31-
public static int ArrayLimit { get; set; } = 100;
31+
public static int ArrayLimit { get; set; } = 20;
3232
public bool MouseInspect { get; set; } = false;
3333

3434
public static string ActiveSceneName

src/CppExplorer.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ProjectGuid>{B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>CppExplorer</RootNamespace>
10+
<RootNamespace>Explorer</RootNamespace>
1111
<AssemblyName>CppExplorer</AssemblyName>
1212
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
@@ -113,9 +113,14 @@
113113
</ItemGroup>
114114
<ItemGroup>
115115
<Compile Include="CppExplorer.cs" />
116+
<Compile Include="Inspectors\Reflection\FieldInfoHolder.cs" />
117+
<Compile Include="Inspectors\Reflection\MemberInfoHolder.cs" />
118+
<Compile Include="Inspectors\Reflection\PropertyInfoHolder.cs" />
119+
<Compile Include="Inspectors\UIWindow.cs" />
116120
<Compile Include="MainMenu\Pages\ConsolePage.cs" />
117121
<Compile Include="MainMenu\Pages\Console\REPL.cs" />
118122
<Compile Include="MainMenu\Pages\Console\REPLHelper.cs" />
123+
<Compile Include="MainMenu\Pages\WindowPage.cs" />
119124
<Compile Include="WindowManager.cs" />
120125
<Compile Include="MainMenu\MainMenu.cs" />
121126
<Compile Include="Inspectors\GameObjectWindow.cs" />

src/Inspectors/GameObjectWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
namespace Explorer
1111
{
12-
public class GameObjectWindow : WindowManager.UIWindow
12+
public class GameObjectWindow : UIWindow
1313
{
14-
public override Il2CppSystem.String Name { get => "GameObject Inspector"; set => Name = value; }
14+
public override string Name { get => "GameObject Inspector"; set => Name = value; }
1515

1616
public GameObject m_object;
1717

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using MelonLoader;
8+
using UnhollowerBaseLib;
9+
10+
namespace Explorer
11+
{
12+
public class FieldInfoHolder : MemberInfoHolder
13+
{
14+
public FieldInfo fieldInfo;
15+
public object m_value;
16+
17+
public FieldInfoHolder(Type _type, FieldInfo _fieldInfo)
18+
{
19+
classType = _type;
20+
fieldInfo = _fieldInfo;
21+
}
22+
23+
public override void UpdateValue(object obj)
24+
{
25+
m_value = fieldInfo.GetValue(fieldInfo.IsStatic ? null : obj);
26+
}
27+
28+
public override void Draw(ReflectionWindow window)
29+
{
30+
UIStyles.DrawMember(ref m_value, ref this.IsExpanded, ref this.arrayOffset, this.fieldInfo, window.m_rect, window.m_object, SetValue);
31+
}
32+
33+
public override void SetValue(object obj)
34+
{
35+
if (fieldInfo.FieldType.IsEnum)
36+
{
37+
if (System.Enum.Parse(fieldInfo.FieldType, m_value.ToString()) is object enumValue && enumValue != null)
38+
{
39+
m_value = enumValue;
40+
}
41+
}
42+
else if (fieldInfo.FieldType.IsPrimitive)
43+
{
44+
if (fieldInfo.FieldType == typeof(float))
45+
{
46+
if (float.TryParse(m_value.ToString(), out float f))
47+
{
48+
m_value = f;
49+
}
50+
else
51+
{
52+
MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a float!");
53+
}
54+
}
55+
else if (fieldInfo.FieldType == typeof(double))
56+
{
57+
if (double.TryParse(m_value.ToString(), out double d))
58+
{
59+
m_value = d;
60+
}
61+
else
62+
{
63+
MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a double!");
64+
}
65+
}
66+
else if (fieldInfo.FieldType != typeof(bool))
67+
{
68+
if (int.TryParse(m_value.ToString(), out int i))
69+
{
70+
m_value = i;
71+
}
72+
else
73+
{
74+
MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to an integer! type: " + fieldInfo.FieldType);
75+
}
76+
}
77+
}
78+
79+
fieldInfo.SetValue(fieldInfo.IsStatic ? null : obj, m_value);
80+
}
81+
}
82+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 abstract class MemberInfoHolder
10+
{
11+
public Type classType;
12+
public bool IsExpanded = false;
13+
public int arrayOffset = 0;
14+
15+
public abstract void Draw(ReflectionWindow window);
16+
public abstract void UpdateValue(object obj);
17+
public abstract void SetValue(object obj);
18+
}
19+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using MelonLoader;
9+
using UnhollowerBaseLib;
10+
11+
namespace Explorer
12+
{
13+
public class PropertyInfoHolder : MemberInfoHolder
14+
{
15+
public PropertyInfo propInfo;
16+
public object m_value;
17+
18+
public PropertyInfoHolder(Type _type, PropertyInfo _propInfo)
19+
{
20+
classType = _type;
21+
propInfo = _propInfo;
22+
}
23+
24+
public override void Draw(ReflectionWindow window)
25+
{
26+
UIStyles.DrawMember(ref m_value, ref this.IsExpanded, ref this.arrayOffset, this.propInfo, window.m_rect, window.m_object, SetValue);
27+
}
28+
29+
public override void UpdateValue(object obj)
30+
{
31+
try
32+
{
33+
if (obj is Il2CppSystem.Object ilObject)
34+
{
35+
var declaringType = this.propInfo.DeclaringType;
36+
if (declaringType == typeof(Il2CppObjectBase))
37+
{
38+
m_value = ilObject.Pointer;
39+
}
40+
else
41+
{
42+
var cast = CppExplorer.Il2CppCast(obj, declaringType);
43+
m_value = this.propInfo.GetValue(cast, null);
44+
}
45+
}
46+
else
47+
{
48+
m_value = this.propInfo.GetValue(obj, null);
49+
}
50+
}
51+
catch (Exception e)
52+
{
53+
MelonLogger.Log("Exception on PropertyInfoHolder.UpdateValue, Name: " + this.propInfo.Name);
54+
MelonLogger.Log(e.GetType() + ", " + e.Message);
55+
56+
var inner = e.InnerException;
57+
while (inner != null)
58+
{
59+
MelonLogger.Log("inner: " + inner.GetType() + ", " + inner.Message);
60+
inner = inner.InnerException;
61+
}
62+
63+
m_value = null;
64+
}
65+
}
66+
67+
public override void SetValue(object obj)
68+
{
69+
try
70+
{
71+
if (propInfo.PropertyType.IsEnum)
72+
{
73+
if (System.Enum.Parse(propInfo.PropertyType, m_value.ToString()) is object enumValue && enumValue != null)
74+
{
75+
m_value = enumValue;
76+
}
77+
}
78+
else if (propInfo.PropertyType.IsPrimitive)
79+
{
80+
if (propInfo.PropertyType == typeof(float))
81+
{
82+
if (float.TryParse(m_value.ToString(), out float f))
83+
{
84+
m_value = f;
85+
}
86+
else
87+
{
88+
MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a float!");
89+
}
90+
}
91+
else if (propInfo.PropertyType == typeof(double))
92+
{
93+
if (double.TryParse(m_value.ToString(), out double d))
94+
{
95+
m_value = d;
96+
}
97+
else
98+
{
99+
MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to a double!");
100+
}
101+
}
102+
else if (propInfo.PropertyType != typeof(bool))
103+
{
104+
if (int.TryParse(m_value.ToString(), out int i))
105+
{
106+
m_value = i;
107+
}
108+
else
109+
{
110+
MelonLogger.LogWarning("Cannot parse " + m_value.ToString() + " to an integer! type: " + propInfo.PropertyType);
111+
}
112+
}
113+
}
114+
115+
var declaring = propInfo.DeclaringType;
116+
var cast = CppExplorer.Il2CppCast(obj, declaring);
117+
118+
propInfo.SetValue(propInfo.GetAccessors()[0].IsStatic ? null : cast, m_value, null);
119+
}
120+
catch
121+
{
122+
//MelonLogger.Log("Exception trying to set property " + this.propInfo.Name);
123+
}
124+
}
125+
}
126+
}

0 commit comments

Comments
 (0)