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

Commit 0769b7e

Browse files
committed
1.6.5
* Add expander to Unity struct inspectors, collapsed by default * `UnityEngine.Color` labels in Reflection Inspector are now the same color as the value for convenience * Cleaned up InputHelper
1 parent 5086dcc commit 0769b7e

File tree

8 files changed

+160
-64
lines changed

8 files changed

+160
-64
lines changed

src/CachedObjects/Struct/CacheColor.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Explorer
99
{
1010
public class CacheColor : CacheObjectBase
1111
{
12+
private bool IsExpanded;
13+
1214
private string r = "0";
1315
private string g = "0";
1416
private string b = "0";
@@ -28,9 +30,30 @@ public override void UpdateValue()
2830

2931
public override void DrawValue(Rect window, float width)
3032
{
31-
GUILayout.Label($"<color=yellow>Color</color>: {((Color)Value).ToString()}", null);
32-
3333
if (CanWrite)
34+
{
35+
if (!IsExpanded)
36+
{
37+
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
38+
{
39+
IsExpanded = true;
40+
}
41+
}
42+
else
43+
{
44+
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
45+
{
46+
IsExpanded = false;
47+
}
48+
}
49+
}
50+
51+
var c = (Color)Value;
52+
GUI.color = c;
53+
GUILayout.Label($"<color=yellow>Color:</color> {c.ToString()}", null);
54+
GUI.color = Color.white;
55+
56+
if (CanWrite && IsExpanded)
3457
{
3558
GUILayout.EndHorizontal();
3659
var whitespace = window.width - width - 90;

src/CachedObjects/Struct/CacheQuaternion.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Explorer
99
{
1010
public class CacheQuaternion : CacheObjectBase
1111
{
12+
private bool IsExpanded;
13+
1214
private string x = "0";
1315
private string y = "0";
1416
private string z = "0";
@@ -26,9 +28,27 @@ public override void UpdateValue()
2628

2729
public override void DrawValue(Rect window, float width)
2830
{
31+
if (CanWrite)
32+
{
33+
if (!IsExpanded)
34+
{
35+
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
36+
{
37+
IsExpanded = true;
38+
}
39+
}
40+
else
41+
{
42+
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
43+
{
44+
IsExpanded = false;
45+
}
46+
}
47+
}
48+
2949
GUILayout.Label($"<color=yellow>Quaternion</color>: {((Quaternion)Value).eulerAngles.ToString()}", null);
3050

31-
if (CanWrite)
51+
if (CanWrite && IsExpanded)
3252
{
3353
GUILayout.EndHorizontal();
3454
var whitespace = window.width - width - 90;

src/CachedObjects/Struct/CacheRect.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Explorer
99
{
1010
public class CacheRect : CacheObjectBase
1111
{
12+
private bool IsExpanded;
13+
1214
private string x = "0";
1315
private string y = "0";
1416
private string w = "0";
@@ -28,9 +30,27 @@ public override void UpdateValue()
2830

2931
public override void DrawValue(Rect window, float width)
3032
{
33+
if (CanWrite)
34+
{
35+
if (!IsExpanded)
36+
{
37+
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
38+
{
39+
IsExpanded = true;
40+
}
41+
}
42+
else
43+
{
44+
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
45+
{
46+
IsExpanded = false;
47+
}
48+
}
49+
}
50+
3151
GUILayout.Label($"<color=yellow>Rect</color>: {((Rect)Value).ToString()}", null);
3252

33-
if (CanWrite)
53+
if (CanWrite && IsExpanded)
3454
{
3555
GUILayout.EndHorizontal();
3656
var whitespace = window.width - width - 90;

src/CachedObjects/Struct/CacheVector.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace Explorer
1010
{
1111
public class CacheVector : CacheObjectBase
1212
{
13+
private bool IsExpanded;
14+
1315
public int VectorSize = 2;
1416

1517
private string x = "0";
@@ -63,9 +65,27 @@ public override void UpdateValue()
6365

6466
public override void DrawValue(Rect window, float width)
6567
{
68+
if (CanWrite)
69+
{
70+
if (!IsExpanded)
71+
{
72+
if (GUILayout.Button("v", new GUILayoutOption[] { GUILayout.Width(25) }))
73+
{
74+
IsExpanded = true;
75+
}
76+
}
77+
else
78+
{
79+
if (GUILayout.Button("^", new GUILayoutOption[] { GUILayout.Width(25) }))
80+
{
81+
IsExpanded = false;
82+
}
83+
}
84+
}
85+
6686
GUILayout.Label($"<color=yellow>Vector{VectorSize}</color>: {(string)m_toStringMethod.Invoke(Value, new object[0])}", null);
6787

68-
if (CanWrite)
88+
if (CanWrite && IsExpanded)
6989
{
7090
GUILayout.EndHorizontal();
7191
var whitespace = window.width - width - 90;

src/CppExplorer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Explorer
1313
public class CppExplorer : MelonMod
1414
{
1515
public const string NAME = "CppExplorer";
16-
public const string VERSION = "1.6.4";
16+
public const string VERSION = "1.6.5";
1717
public const string AUTHOR = "Sinai";
1818
public const string GUID = "com.sinai.cppexplorer";
1919

@@ -50,7 +50,7 @@ public override void OnApplicationStart()
5050
{
5151
Instance = this;
5252

53-
InputHelper.CheckInput();
53+
InputHelper.Init();
5454

5555
new MainMenu();
5656
new WindowManager();

src/CppExplorer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<ProjectGuid>{B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}</ProjectGuid>
88
<OutputType>Library</OutputType>
@@ -24,6 +24,7 @@
2424
<Prefer32Bit>false</Prefer32Bit>
2525
</PropertyGroup>
2626
<ItemGroup>
27+
<!-- Replace the '..\Steam\..` references with ones from your game (make sure to use the 'MelonLoader\' folder) -->
2728
<Reference Include="Il2Cppmscorlib">
2829
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\Il2Cppmscorlib.dll</HintPath>
2930
<Private>False</Private>
@@ -46,7 +47,6 @@
4647
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
4748
<Private>False</Private>
4849
</Reference>
49-
<!-- Replace these references with ones from your game (..\MelonLoader\ folder) -->
5050
<Reference Include="UnityEngine">
5151
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.dll</HintPath>
5252
<Private>False</Private>

src/CppExplorer.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Global
1010
Release|Any CPU = Release|Any CPU
1111
EndGlobalSection
1212
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13-
{B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
14-
{B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release|Any CPU.Build.0 = Release|Any CPU
13+
{B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release|Any CPU.ActiveCfg = Debug|Any CPU
14+
{B21DBDE3-5D6F-4726-93AB-CC3CC68BAE7D}.Release|Any CPU.Build.0 = Debug|Any CPU
1515
EndGlobalSection
1616
GlobalSection(SolutionProperties) = preSolution
1717
HideSolutionNode = FALSE

src/Helpers/InputHelper.cs

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,93 +15,106 @@ namespace Explorer
1515
/// </summary>
1616
public static class InputHelper
1717
{
18-
public static void CheckInput()
19-
{
20-
if (Input == null)
21-
{
22-
MelonLogger.Log("UnityEngine.Input is null, trying to load manually....");
23-
24-
if ((TryLoad("UnityEngine.InputLegacyModule.dll") || TryLoad("UnityEngine.CoreModule.dll")) && Input != null)
25-
{
26-
MelonLogger.Log("Ok!");
27-
}
28-
else
29-
{
30-
MelonLogger.Log("Could not load Input module!");
31-
}
32-
33-
bool TryLoad(string module)
34-
{
35-
var path = $@"MelonLoader\Managed\{module}";
36-
if (!File.Exists(path)) return false;
37-
38-
try
39-
{
40-
Assembly.Load(File.ReadAllBytes(path));
41-
return true;
42-
}
43-
catch (Exception e)
44-
{
45-
MelonLogger.Log(e.GetType() + ", " + e.Message);
46-
return false;
47-
}
48-
}
49-
}
50-
}
18+
// If Input module failed to load at all
19+
public static bool NO_INPUT;
5120

52-
public static Type Input => _input ?? (_input = ReflectionHelpers.GetTypeByName("UnityEngine.Input"));
21+
// Base UnityEngine.Input class
22+
private static Type Input => _input ?? (_input = ReflectionHelpers.GetTypeByName("UnityEngine.Input"));
5323
private static Type _input;
5424

55-
private static PropertyInfo MousePosInfo => _mousePosition ?? (_mousePosition = Input?.GetProperty("mousePosition"));
25+
// Cached member infos
5626
private static PropertyInfo _mousePosition;
57-
58-
private static MethodInfo GetKeyInfo => _getKey ?? (_getKey = Input?.GetMethod("GetKey", new Type[] { typeof(KeyCode) }));
5927
private static MethodInfo _getKey;
60-
61-
private static MethodInfo GetKeyDownInfo => _getKeyDown ?? (_getKeyDown = Input?.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) }));
6228
private static MethodInfo _getKeyDown;
63-
64-
private static MethodInfo GetMouseButtonInfo => _getMouseButton ?? (_getMouseButton = Input?.GetMethod("GetMouseButton", new Type[] { typeof(int) }));
6529
private static MethodInfo _getMouseButton;
66-
67-
private static MethodInfo GetMouseButtonDownInfo => _getMouseButtonDown ?? (_getMouseButtonDown = Input?.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) }));
6830
private static MethodInfo _getMouseButtonDown;
6931

32+
public static void Init()
33+
{
34+
if (Input == null && !TryManuallyLoadInput())
35+
{
36+
NO_INPUT = true;
37+
return;
38+
}
39+
40+
// Cache reflection now that we know Input is loaded
41+
42+
_mousePosition = Input.GetProperty("mousePosition");
43+
44+
_getKey = Input.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
45+
_getKeyDown = Input.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
46+
_getMouseButton = Input.GetMethod("GetMouseButton", new Type[] { typeof(int) });
47+
_getMouseButtonDown = Input.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
48+
}
49+
7050
#pragma warning disable IDE1006 // Camel-case property (Unity style)
7151
public static Vector3 mousePosition
7252
{
7353
get
7454
{
75-
if (Input == null) return Vector3.zero;
76-
return (Vector3)MousePosInfo.GetValue(null);
55+
if (NO_INPUT) return Vector3.zero;
56+
return (Vector3)_mousePosition.GetValue(null);
7757
}
7858
}
7959
#pragma warning restore IDE1006
8060

8161
public static bool GetKeyDown(KeyCode key)
8262
{
83-
if (Input == null) return false;
84-
return (bool)GetKeyDownInfo.Invoke(null, new object[] { key });
63+
if (NO_INPUT) return false;
64+
return (bool)_getKeyDown.Invoke(null, new object[] { key });
8565
}
8666

8767
public static bool GetKey(KeyCode key)
8868
{
89-
if (Input == null) return false;
90-
return (bool)GetKeyInfo.Invoke(null, new object[] { key });
69+
if (NO_INPUT) return false;
70+
return (bool)_getKey.Invoke(null, new object[] { key });
9171
}
9272

9373
/// <param name="btn">1 = left, 2 = middle, 3 = right, etc</param>
9474
public static bool GetMouseButtonDown(int btn)
9575
{
96-
if (Input == null) return false;
97-
return (bool)GetMouseButtonDownInfo.Invoke(null, new object[] { btn });
76+
if (NO_INPUT) return false;
77+
return (bool)_getMouseButtonDown.Invoke(null, new object[] { btn });
9878
}
9979

10080
/// <param name="btn">1 = left, 2 = middle, 3 = right, etc</param>
10181
public static bool GetMouseButton(int btn)
10282
{
103-
if (Input == null) return false;
104-
return (bool)GetMouseButtonInfo.Invoke(null, new object[] { btn });
83+
if (NO_INPUT) return false;
84+
return (bool)_getMouseButton.Invoke(null, new object[] { btn });
85+
}
86+
87+
private static bool TryManuallyLoadInput()
88+
{
89+
MelonLogger.Log("UnityEngine.Input is null, trying to load manually....");
90+
91+
if ((TryLoad("UnityEngine.InputLegacyModule.dll") || TryLoad("UnityEngine.CoreModule.dll")) && Input != null)
92+
{
93+
MelonLogger.Log("Ok!");
94+
return true;
95+
}
96+
else
97+
{
98+
MelonLogger.Log("Could not load Input module!");
99+
return false;
100+
}
101+
102+
bool TryLoad(string module)
103+
{
104+
var path = $@"MelonLoader\Managed\{module}";
105+
if (!File.Exists(path)) return false;
106+
107+
try
108+
{
109+
Assembly.Load(File.ReadAllBytes(path));
110+
return true;
111+
}
112+
catch (Exception e)
113+
{
114+
MelonLogger.Log(e.GetType() + ", " + e.Message);
115+
return false;
116+
}
117+
}
105118
}
106119
}
107120
}

0 commit comments

Comments
 (0)