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

Commit 8f02562

Browse files
committed
3.3.2
* Added InteractiveColor UI editor to make changing a Color easier * Added a "Scene Loader" helper which allows you to load any Scene that the game was built with. In some cases you may not find all the Scenes that the game uses, they may be loaded through AssetBundles or other means and won't show up here yet * Adjusted the SceneExplorer UI, the "Hide" button is now always on the left of the window * * Handled some errors related to UI unstripping that could occur in rare cases
1 parent 89f1376 commit 8f02562

29 files changed

+441
-229
lines changed

src/Core/ReflectionUtility.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace UnityExplorer.Core
1111
{
1212
public static class ReflectionUtility
1313
{
14-
public const BF CommonFlags = BF.Public | BF.Instance | BF.NonPublic | BF.Static;
14+
public const BF AllFlags = BF.Public | BF.Instance | BF.NonPublic | BF.Static;
1515

1616
/// <summary>
1717
/// Helper for IL2CPP to get the underlying true Type (Unhollowed) of the object.
@@ -163,6 +163,32 @@ public static IEnumerable<Type> TryGetTypes(this Assembly asm)
163163
}
164164
}
165165

166+
internal static Dictionary<Type, Dictionary<string, FieldInfo>> s_cachedFieldInfos = new Dictionary<Type, Dictionary<string, FieldInfo>>();
167+
168+
public static FieldInfo GetFieldInfo(Type type, string fieldName)
169+
{
170+
if (!s_cachedFieldInfos.ContainsKey(type))
171+
s_cachedFieldInfos.Add(type, new Dictionary<string, FieldInfo>());
172+
173+
if (!s_cachedFieldInfos[type].ContainsKey(fieldName))
174+
s_cachedFieldInfos[type].Add(fieldName, type.GetField(fieldName, AllFlags));
175+
176+
return s_cachedFieldInfos[type][fieldName];
177+
}
178+
179+
internal static Dictionary<Type, Dictionary<string, PropertyInfo>> s_cachedPropInfos = new Dictionary<Type, Dictionary<string, PropertyInfo>>();
180+
181+
public static PropertyInfo GetPropertyInfo(Type type, string propertyName)
182+
{
183+
if (!s_cachedPropInfos.ContainsKey(type))
184+
s_cachedPropInfos.Add(type, new Dictionary<string, PropertyInfo>());
185+
186+
if (!s_cachedPropInfos[type].ContainsKey(propertyName))
187+
s_cachedPropInfos[type].Add(propertyName, type.GetProperty(propertyName, AllFlags));
188+
189+
return s_cachedPropInfos[type][propertyName];
190+
}
191+
166192
/// <summary>
167193
/// Helper to display a simple "{ExceptionType}: {Message}" of the exception, and optionally use the inner-most exception.
168194
/// </summary>

src/Core/Runtime/Il2Cpp/Il2CppProvider.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Collections;
1414
using UnityEngine.UI;
1515
using UnityExplorer.Core.Input;
16+
using UnityEngine.EventSystems;
1617

1718
namespace UnityExplorer.Core.Runtime.Il2Cpp
1819
{
@@ -121,17 +122,42 @@ public static int GetRootCount(int handle)
121122
.Invoke(handle);
122123
}
123124

124-
// Custom check for il2cpp input pointer event
125+
internal static bool? s_doPropertiesExist;
125126

126-
public override void CheckInputPointerEvent()
127+
public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null)
127128
{
128-
// Some IL2CPP games behave weird with multiple UI Input Systems, some fixes for them.
129-
var evt = InputManager.InputPointerEvent;
130-
if (evt != null)
129+
if (s_doPropertiesExist == null)
131130
{
132-
if (!evt.eligibleForClick && evt.selectedObject)
133-
evt.eligibleForClick = true;
131+
var prop = ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "normalColor") as PropertyInfo;
132+
s_doPropertiesExist = prop != null && prop.CanWrite;
134133
}
134+
135+
colors.colorMultiplier = 1;
136+
137+
object boxed = (object)colors;
138+
139+
if (s_doPropertiesExist == true)
140+
{
141+
if (normal != null)
142+
ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "normalColor").SetValue(boxed, (Color)normal);
143+
if (pressed != null)
144+
ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "pressedColor").SetValue(boxed, (Color)pressed);
145+
if (highlighted != null)
146+
ReflectionUtility.GetPropertyInfo(typeof(ColorBlock), "highlightedColor").SetValue(boxed, (Color)highlighted);
147+
}
148+
else if (s_doPropertiesExist == false)
149+
{
150+
if (normal != null)
151+
ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_NormalColor").SetValue(boxed, (Color)normal);
152+
if (pressed != null)
153+
ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_PressedColor").SetValue(boxed, (Color)pressed);
154+
if (highlighted != null)
155+
ReflectionUtility.GetFieldInfo(typeof(ColorBlock), "m_HighlightedColor").SetValue(boxed, (Color)highlighted);
156+
}
157+
158+
colors = (ColorBlock)boxed;
159+
160+
return colors;
135161
}
136162
}
137163
}

src/Core/Runtime/Mono/MonoProvider.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public override string LayerToName(int layer)
4343
public override UnityEngine.Object[] FindObjectsOfTypeAll(Type type)
4444
=> Resources.FindObjectsOfTypeAll(type);
4545

46-
private static readonly FieldInfo fi_Scene_handle = typeof(Scene).GetField("m_Handle", ReflectionUtility.CommonFlags);
46+
private static readonly FieldInfo fi_Scene_handle = typeof(Scene).GetField("m_Handle", ReflectionUtility.AllFlags);
4747

4848
public override int GetSceneHandle(Scene scene)
4949
{
@@ -60,9 +60,18 @@ public override int GetRootCount(Scene scene)
6060
return scene.rootCount;
6161
}
6262

63-
public override void CheckInputPointerEvent()
63+
public override ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null)
6464
{
65-
// Not necessary afaik
65+
if (normal != null)
66+
colors.normalColor = (Color)normal;
67+
68+
if (highlighted != null)
69+
colors.highlightedColor = (Color)highlighted;
70+
71+
if (pressed != null)
72+
colors.pressedColor = (Color)pressed;
73+
74+
return colors;
6675
}
6776
}
6877
}

src/Core/Runtime/Mono/MonoTextureUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static byte[] EncodeToPNGSafe(Texture2D tex)
5252
private static MethodInfo GetEncodeToPNGMethod()
5353
{
5454
if (ReflectionUtility.GetTypeByName("UnityEngine.ImageConversion") is Type imageConversion)
55-
return m_encodeToPNGMethod = imageConversion.GetMethod("EncodeToPNG", ReflectionUtility.CommonFlags);
55+
return m_encodeToPNGMethod = imageConversion.GetMethod("EncodeToPNG", ReflectionUtility.AllFlags);
5656

57-
var method = typeof(Texture2D).GetMethod("EncodeToPNG", ReflectionUtility.CommonFlags);
57+
var method = typeof(Texture2D).GetMethod("EncodeToPNG", ReflectionUtility.AllFlags);
5858
if (method != null)
5959
return m_encodeToPNGMethod = method;
6060

src/Core/Runtime/RuntimeProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public static void Init() =>
5252

5353
public abstract int GetRootCount(Scene scene);
5454

55-
public abstract void CheckInputPointerEvent();
55+
public abstract ColorBlock SetColorBlock(ColorBlock colors, Color? normal = null, Color? highlighted = null, Color? pressed = null);
5656
}
5757
}

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace UnityExplorer
1212
public class ExplorerCore
1313
{
1414
public const string NAME = "UnityExplorer";
15-
public const string VERSION = "3.3.1";
15+
public const string VERSION = "3.3.2";
1616
public const string AUTHOR = "Sinai";
1717
public const string GUID = "com.sinai.unityexplorer";
1818

src/Loader/ML/MelonLoaderConfigHandler.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Text;
88
using UnityEngine;
9+
using UnityExplorer.Core;
910
using UnityExplorer.Core.Config;
1011

1112
namespace UnityExplorer.Loader.ML
@@ -66,6 +67,11 @@ public override T GetConfigValue<T>(ConfigElement<T> config)
6667
return default;
6768
}
6869

70+
public override void OnAnyConfigChanged()
71+
{
72+
MelonPreferences.Save();
73+
}
74+
6975
public override void SaveConfig()
7076
{
7177
MelonPreferences.Save();

src/UI/CacheObject/CacheConfigEntry.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,9 @@ public override void UpdateValue()
4949
public override void SetValue()
5050
{
5151
RefConfig.BoxedValue = IValue.Value;
52-
ConfigManager.Handler.OnAnyConfigChanged();
5352
}
5453

5554
internal GameObject m_mainGroup;
56-
//internal GameObject m_leftGroup;
57-
//internal GameObject m_rightGroup;
58-
//internal GameObject m_secondRow;
5955

6056
internal override void ConstructUI()
6157
{
@@ -66,11 +62,6 @@ internal override void ConstructUI()
6662
var horiGroup = UIFactory.CreateHorizontalGroup(m_mainGroup, "ConfigEntryHolder", false, false, true, true, childAlignment: TextAnchor.MiddleLeft);
6763
UIFactory.SetLayoutElement(horiGroup, minHeight: 30, flexibleHeight: 0);
6864

69-
//// left group
70-
71-
//m_leftGroup = UIFactory.CreateHorizontalGroup(horiGroup, "ConfigTitleGroup", false, false, true, true, 4, default, new Color(1, 1, 1, 0));
72-
//UIFactory.SetLayoutElement(m_leftGroup, minHeight: 25, flexibleHeight: 0, minWidth: 200, flexibleWidth: 0);
73-
7465
// config entry label
7566

7667
var configLabel = UIFactory.CreateLabel(horiGroup, "ConfigLabel", this.RefConfig.Name, TextAnchor.MiddleLeft);
@@ -91,20 +82,11 @@ internal override void ConstructUI()
9182
new Color(0.3f, 0.3f, 0.3f));
9283
UIFactory.SetLayoutElement(defaultButton.gameObject, minWidth: 80, minHeight: 22, flexibleWidth: 0);
9384

94-
//// right group
95-
96-
//m_rightGroup = UIFactory.CreateVerticalGroup(horiGroup, "ConfigValueGroup", false, false, true, true, 4, default, new Color(1, 1, 1, 0));
97-
//UIFactory.SetLayoutElement(m_rightGroup, minHeight: 25, minWidth: 150, flexibleHeight: 0, flexibleWidth: 5000);
98-
9985
// Description label
10086

10187
var desc = UIFactory.CreateLabel(m_mainGroup, "Description", $"<i>{RefConfig.Description}</i>", TextAnchor.MiddleLeft, Color.grey);
10288
UIFactory.SetLayoutElement(desc.gameObject, minWidth: 250, minHeight: 20, flexibleWidth: 9999, flexibleHeight: 0);
10389

104-
//// Second row (IValue)
105-
106-
//m_secondRow = UIFactory.CreateHorizontalGroup(m_mainGroup, "DescriptionRow", false, false, true, true, 4, new Color(0.08f, 0.08f, 0.08f));
107-
10890
// IValue
10991

11092
if (IValue != null)

src/UI/CacheObject/CacheMember.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,8 @@ internal void ConstructEvaluateButtons(GameObject argsHolder)
320320
UIFactory.SetLayoutElement(evalGroupObj, minHeight: 25, flexibleHeight: 0, flexibleWidth: 5000);
321321

322322
var colors = new ColorBlock();
323-
colors.normalColor = new Color(0.4f, 0.4f, 0.4f);
324-
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
325-
colors.pressedColor = new Color(0.3f, 0.3f, 0.3f);
323+
colors = RuntimeProvider.Instance.SetColorBlock(colors, new Color(0.4f, 0.4f, 0.4f),
324+
new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f));
326325

327326
var evalButton = UIFactory.CreateButton(evalGroupObj,
328327
"EvalButton",
@@ -346,9 +345,7 @@ internal void ConstructEvaluateButtons(GameObject argsHolder)
346345
argsHolder.SetActive(true);
347346
m_isEvaluating = true;
348347
evalText.text = "Evaluate";
349-
colors = evalButton.colors;
350-
colors.normalColor = new Color(0.3f, 0.6f, 0.3f);
351-
evalButton.colors = colors;
348+
evalButton.colors = RuntimeProvider.Instance.SetColorBlock(evalButton.colors, new Color(0.3f, 0.6f, 0.3f));
352349

353350
cancelButton.gameObject.SetActive(true);
354351
}
@@ -368,19 +365,16 @@ internal void ConstructEvaluateButtons(GameObject argsHolder)
368365
m_isEvaluating = false;
369366

370367
evalText.text = $"Evaluate ({ParamCount})";
371-
colors = evalButton.colors;
372-
colors.normalColor = new Color(0.4f, 0.4f, 0.4f);
373-
evalButton.colors = colors;
368+
evalButton.colors = RuntimeProvider.Instance.SetColorBlock(evalButton.colors, new Color(0.4f, 0.4f, 0.4f));
374369
});
375370
}
376371
else if (this is CacheMethod)
377372
{
378373
// simple method evaluate button
379374

380375
var colors = new ColorBlock();
381-
colors.normalColor = new Color(0.4f, 0.4f, 0.4f);
382-
colors.highlightedColor = new Color(0.4f, 0.7f, 0.4f);
383-
colors.pressedColor = new Color(0.3f, 0.3f, 0.3f);
376+
colors = RuntimeProvider.Instance.SetColorBlock(colors, new Color(0.4f, 0.4f, 0.4f),
377+
new Color(0.4f, 0.7f, 0.4f), new Color(0.3f, 0.3f, 0.3f));
384378

385379
var evalButton = UIFactory.CreateButton(m_rightGroup, "EvalButton", "Evaluate", () => { (this as CacheMethod).Evaluate(); }, colors);
386380
UIFactory.SetLayoutElement(evalButton.gameObject, minWidth: 100, minHeight: 22, flexibleWidth: 0);

src/UI/InteractiveValues/InteractiveBool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public override void ConstructUI(GameObject parent, GameObject subGroup)
8888

8989
if (Owner.CanWrite)
9090
{
91-
var toggleObj = UIFactory.CreateToggle(m_valueContent, "InteractiveBoolToggle", out m_toggle, out _, new Color(0.1f, 0.1f, 0.1f));
91+
var toggleObj = UIFactory.CreateToggle(m_mainContent, "InteractiveBoolToggle", out m_toggle, out _, new Color(0.1f, 0.1f, 0.1f));
9292
UIFactory.SetLayoutElement(toggleObj, minWidth: 24);
9393
m_toggle.onValueChanged.AddListener(OnToggleValueChanged);
9494

9595
m_baseLabel.transform.SetAsLastSibling();
9696

97-
m_applyBtn = UIFactory.CreateButton(m_valueContent,
97+
m_applyBtn = UIFactory.CreateButton(m_mainContent,
9898
"ApplyButton",
9999
"Apply",
100100
() => { Owner.SetValue(); },

0 commit comments

Comments
 (0)