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

Commit 544009d

Browse files
committed
3.1.7
* Added standalone release build (thanks @Alloc86) * Improved formatting for ToString methods which accept an IFormatProvider * When editing a struct, the reference to the parent member will now be updated if you modify the struct values.
1 parent fdfaaad commit 544009d

File tree

11 files changed

+121
-11
lines changed

11 files changed

+121
-11
lines changed

src/ExplorerCore.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Reflection;
34
using UnityEngine;
45
using UnityEngine.SceneManagement;
56
using UnityExplorer.Config;
@@ -16,14 +17,30 @@ namespace UnityExplorer
1617
public class ExplorerCore
1718
{
1819
public const string NAME = "UnityExplorer";
19-
public const string VERSION = "3.1.6";
20+
public const string VERSION = "3.1.7";
2021
public const string AUTHOR = "Sinai";
2122
public const string GUID = "com.sinai.unityexplorer";
2223

2324
#if ML
2425
public const string EXPLORER_FOLDER = @"Mods\UnityExplorer";
2526
#elif BIE
2627
public static string EXPLORER_FOLDER = Path.Combine(BepInEx.Paths.ConfigPath, "UnityExplorer");
28+
#elif STANDALONE
29+
public static string EXPLORER_FOLDER
30+
{
31+
get
32+
{
33+
if (s_explorerFolder == null)
34+
{
35+
s_explorerFolder = (new Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;
36+
s_explorerFolder = Uri.UnescapeDataString(s_explorerFolder);
37+
s_explorerFolder = Path.GetDirectoryName(s_explorerFolder);
38+
}
39+
40+
return s_explorerFolder;
41+
}
42+
}
43+
private static string s_explorerFolder;
2744
#endif
2845

2946
public static ExplorerCore Instance { get; private set; }
@@ -166,6 +183,12 @@ private void OnUnityLog(string message, string stackTrace, LogType type)
166183
}
167184
}
168185

186+
#if STANDALONE
187+
public static Action<string> OnLogMessage;
188+
public static Action<string> OnLogWarning;
189+
public static Action<string> OnLogError;
190+
#endif
191+
169192
public static void Log(object message, bool unity = false)
170193
{
171194
DebugConsole.Log(message?.ToString());
@@ -175,8 +198,10 @@ public static void Log(object message, bool unity = false)
175198

176199
#if ML
177200
MelonLoader.MelonLogger.Log(message?.ToString());
178-
#else
201+
#elif BIE
179202
ExplorerBepInPlugin.Logging?.LogMessage(message?.ToString());
203+
#elif STANDALONE
204+
OnLogMessage?.Invoke(message?.ToString());
180205
#endif
181206
}
182207

@@ -189,8 +214,10 @@ public static void LogWarning(object message, bool unity = false)
189214

190215
#if ML
191216
MelonLoader.MelonLogger.LogWarning(message?.ToString());
192-
#else
193-
ExplorerBepInPlugin.Logging?.LogWarning(message?.ToString());
217+
#elif BIE
218+
ExplorerBepInPlugin.Logging?.LogWarning(message?.ToString());
219+
#elif STANDALONE
220+
OnLogWarning?.Invoke(message?.ToString());
194221
#endif
195222
}
196223

@@ -203,8 +230,10 @@ public static void LogError(object message, bool unity = false)
203230

204231
#if ML
205232
MelonLoader.MelonLogger.LogError(message?.ToString());
206-
#else
207-
ExplorerBepInPlugin.Logging?.LogError(message?.ToString());
233+
#elif BIE
234+
ExplorerBepInPlugin.Logging?.LogError(message?.ToString());
235+
#elif STANDALONE
236+
OnLogError?.Invoke(message?.ToString());
208237
#endif
209238
}
210239

src/ExplorerStandalone.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#if STANDALONE
2+
using HarmonyLib;
3+
4+
namespace UnityExplorer
5+
{
6+
public class ExplorerStandalone
7+
{
8+
public static readonly Harmony HarmonyInstance = new Harmony(ExplorerCore.GUID);
9+
}
10+
}
11+
#endif

src/Inspectors/InspectorManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void Update()
3838
}
3939
}
4040

41-
public void Inspect(object obj)
41+
public void Inspect(object obj, CacheObjectBase parentMember = null)
4242
{
4343
#if CPP
4444
obj = obj.Il2CppCast(ReflectionHelpers.GetActualType(obj));
@@ -76,6 +76,9 @@ public void Inspect(object obj)
7676
else
7777
inspector = new InstanceInspector(obj);
7878

79+
if (inspector is ReflectionInspector ri)
80+
ri.ParentMember = parentMember;
81+
7982
m_currentInspectors.Add(inspector);
8083
SetInspectorTab(inspector);
8184
}

src/Inspectors/Reflection/CacheObject/CacheField.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public override void SetValue()
3333
{
3434
var fi = MemInfo as FieldInfo;
3535
fi.SetValue(fi.IsStatic ? null : DeclaringInstance, IValue.Value);
36+
37+
if (this.ParentInspector?.ParentMember != null)
38+
this.ParentInspector.ParentMember.SetValue();
3639
}
3740
}
3841
}

src/Inspectors/Reflection/CacheObject/CacheMember.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class CacheMember : CacheObjectBase
1919

2020
public override Type FallbackType { get; }
2121

22+
public ReflectionInspector ParentInspector { get; set; }
2223
public MemberInfo MemInfo { get; set; }
2324
public Type DeclaringType { get; set; }
2425
public object DeclaringInstance { get; set; }

src/Inspectors/Reflection/CacheObject/CacheProperty.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public override void SetValue()
6363
var target = pi.GetAccessors()[0].IsStatic ? null : DeclaringInstance;
6464

6565
pi.SetValue(target, IValue.Value, ParseArguments());
66+
67+
if (this.ParentInspector?.ParentMember != null)
68+
this.ParentInspector.ParentMember.SetValue();
6669
}
6770
}
6871
}

src/Inspectors/Reflection/InteractiveValue/InteractiveValue.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ internal virtual void OnToggleSubcontent(bool toggle)
176176
ConstructSubcontent();
177177
}
178178

179+
internal MethodInfo m_toStringMethod;
180+
internal MethodInfo m_toStringFormatMethod;
181+
internal bool m_gotToStringMethods;
182+
179183
public string GetDefaultLabel(bool updateType = true)
180184
{
181185
var valueType = Value?.GetType() ?? this.FallbackType;
@@ -205,8 +209,33 @@ public string GetDefaultLabel(bool updateType = true)
205209
}
206210
else
207211
{
208-
var toString = (string)valueType.GetMethod("ToString", new Type[0])?.Invoke(Value, null)
209-
?? Value.ToString();
212+
if (!m_gotToStringMethods)
213+
{
214+
m_gotToStringMethods = true;
215+
216+
m_toStringMethod = valueType.GetMethod("ToString", new Type[0]);
217+
m_toStringFormatMethod = valueType.GetMethod("ToString", new Type[] { typeof(string) });
218+
219+
// test format method actually works
220+
try
221+
{
222+
m_toStringFormatMethod.Invoke(Value, new object[] { "F3" });
223+
}
224+
catch
225+
{
226+
m_toStringFormatMethod = null;
227+
}
228+
}
229+
230+
string toString;
231+
if (m_toStringFormatMethod != null)
232+
{
233+
toString = (string)m_toStringFormatMethod.Invoke(Value, new object[] { "F3" });
234+
}
235+
else
236+
{
237+
toString = (string)m_toStringMethod.Invoke(Value, new object[0]);
238+
}
210239

211240
var fullnametemp = valueType.ToString();
212241
if (fullnametemp.StartsWith("Il2CppSystem"))
@@ -303,7 +332,7 @@ public virtual void ConstructUI(GameObject parent, GameObject subGroup)
303332
void OnInspectClicked()
304333
{
305334
if (!Value.IsNullOrDestroyed(false))
306-
InspectorManager.Instance.Inspect(this.Value);
335+
InspectorManager.Instance.Inspect(this.Value, this.Owner);
307336
}
308337

309338
m_inspectButton.SetActive(false);

src/Inspectors/Reflection/ReflectionInspector.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ private static void OnContainerResized()
5858

5959
public override string TabLabel => m_targetTypeShortName;
6060

61+
internal CacheObjectBase ParentMember { get; set; }
62+
6163
internal readonly Type m_targetType;
6264
internal readonly string m_targetTypeShortName;
6365

@@ -202,6 +204,8 @@ public void CacheMembers(Type type)
202204
list.Add(new CacheProperty(pi, target, m_scrollContent));
203205
else
204206
list.Add(new CacheField(fi, target, m_scrollContent));
207+
208+
list.Last().ParentInspector = this;
205209
}
206210
catch (Exception e)
207211
{

src/UI/ForceUnlockCursor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ private static void TryPatch(Type type, string property, HarmonyMethod patch, bo
105105
var harmony =
106106
#if ML
107107
ExplorerMelonMod.Instance.harmonyInstance;
108-
#else
108+
#elif BIE
109109
ExplorerBepInPlugin.HarmonyInstance;
110+
#elif STANDALONE
111+
ExplorerStandalone.HarmonyInstance;
110112
#endif
111113

112114
System.Reflection.PropertyInfo prop = type.GetProperty(property);

src/UnityExplorer.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@
6868
<IsMelonLoader>false</IsMelonLoader>
6969
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7070
</PropertyGroup>
71+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_STANDALONE_Mono|AnyCPU'">
72+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
73+
<OutputPath>..\Release\UnityExplorer.Standalone.Mono\</OutputPath>
74+
<DefineConstants>MONO,STANDALONE</DefineConstants>
75+
<AssemblyName>UnityExplorer.STANDALONE.Mono</AssemblyName>
76+
<IsCpp>false</IsCpp>
77+
<IsMelonLoader>false</IsMelonLoader>
78+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
79+
</PropertyGroup>
80+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_STANDALONE_Cpp|AnyCPU'">
81+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
82+
<OutputPath>..\Release\UnityExplorer.Standalone.Il2Cpp\</OutputPath>
83+
<DefineConstants>CPP,STANDALONE</DefineConstants>
84+
<AssemblyName>UnityExplorer.STANDALONE.IL2CPP</AssemblyName>
85+
<IsCpp>true</IsCpp>
86+
<IsMelonLoader>false</IsMelonLoader>
87+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88+
</PropertyGroup>
7189
<ItemGroup>
7290
<Reference Include="INIFileParser, Version=2.5.2.0, Culture=neutral, PublicKeyToken=79af7b307b65cf3c, processorArchitecture=MSIL">
7391
<HintPath>packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll</HintPath>
@@ -217,6 +235,7 @@
217235
</Reference>
218236
</ItemGroup>
219237
<ItemGroup>
238+
<Compile Include="ExplorerStandalone.cs" />
220239
<Compile Include="Helpers\EventHelper.cs" />
221240
<Compile Include="Inspectors\MouseInspector.cs" />
222241
<Compile Include="Inspectors\Reflection\CacheObject\CacheEnumerated.cs" />

0 commit comments

Comments
 (0)