Cleanups, method summaries, bump version

This commit is contained in:
Sinai 2021-03-12 18:41:57 +11:00
parent f10a462b00
commit 9efb9581f5
5 changed files with 39 additions and 32 deletions

View File

@ -15,7 +15,7 @@ namespace UnityExplorer
public class ExplorerCore public class ExplorerCore
{ {
public const string NAME = "UnityExplorer"; public const string NAME = "UnityExplorer";
public const string VERSION = "3.2.1"; public const string VERSION = "3.2.2";
public const string AUTHOR = "Sinai"; public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer"; public const string GUID = "com.sinai.unityexplorer";

View File

@ -11,20 +11,27 @@ namespace UnityExplorer.Helpers
{ {
private static readonly Dictionary<string, Delegate> iCallCache = new Dictionary<string, Delegate>(); private static readonly Dictionary<string, Delegate> iCallCache = new Dictionary<string, Delegate>();
public static T GetICall<T>(string iCallName) where T : Delegate /// <summary>
/// Helper to get and cache an iCall by providing the signature (eg. "UnityEngine.Resources::FindObjectsOfTypeAll").
/// </summary>
/// <typeparam name="T">The Type of Delegate to provide for the iCall.</typeparam>
/// <param name="signature">The signature of the iCall you want to get.</param>
/// <returns>The <typeparamref name="T"/> delegate if successful.</returns>
/// <exception cref="MissingMethodException">If the iCall could not be found.</exception>
public static T GetICall<T>(string signature) where T : Delegate
{ {
if (iCallCache.ContainsKey(iCallName)) if (iCallCache.ContainsKey(signature))
return (T)iCallCache[iCallName]; return (T)iCallCache[signature];
IntPtr ptr = il2cpp_resolve_icall(iCallName); IntPtr ptr = il2cpp_resolve_icall(signature);
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
{ {
throw new MissingMethodException($"Could not resolve internal call by name '{iCallName}'!"); throw new MissingMethodException($"Could not resolve internal call by name '{signature}'!");
} }
Delegate iCall = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T)); Delegate iCall = Marshal.GetDelegateForFunctionPointer(ptr, typeof(T));
iCallCache.Add(iCallName, iCall); iCallCache.Add(signature, iCall);
return (T)iCall; return (T)iCall;
} }

View File

@ -381,7 +381,7 @@ namespace UnityExplorer.Inspectors.Reflection
argLabelLayout.minHeight = 25; argLabelLayout.minHeight = 25;
var argText = argLabelObj.GetComponent<Text>(); var argText = argLabelObj.GetComponent<Text>();
var argTypeTxt = UISyntaxHighlight.ParseFullSyntax(arg.ParameterType, false); var argTypeTxt = UISyntaxHighlight.ParseFullSyntax(arg.ParameterType, false);
argText.text = $"{argTypeTxt} <color={UISyntaxHighlight.Local}>{arg.Name}</color>"; argText.text = $"{argTypeTxt} <color={UISyntaxHighlight.LOCAL_ARG}>{arg.Name}</color>";
var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1); var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1);
var argInputLayout = argInputObj.AddComponent<LayoutElement>(); var argInputLayout = argInputObj.AddComponent<LayoutElement>();

View File

@ -168,7 +168,7 @@ namespace UnityExplorer.Inspectors.Reflection
//var argLayout = argLabelObj.AddComponent<LayoutElement>(); //var argLayout = argLabelObj.AddComponent<LayoutElement>();
//argLayout.minWidth = 20; //argLayout.minWidth = 20;
var argText = argLabelObj.GetComponent<Text>(); var argText = argLabelObj.GetComponent<Text>();
argText.text = $"{constrainTxt} <color={UISyntaxHighlight.Enum}>{arg.Name}</color>"; argText.text = $"{constrainTxt} <color={UISyntaxHighlight.CONST_VAR}>{arg.Name}</color>";
var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1); var argInputObj = UIFactory.CreateInputField(rowObj, 14, (int)TextAnchor.MiddleLeft, 1);
var argInputLayout = argInputObj.AddComponent<LayoutElement>(); var argInputLayout = argInputObj.AddComponent<LayoutElement>();

View File

@ -8,36 +8,36 @@ namespace UnityExplorer.UI
{ {
public class UISyntaxHighlight public class UISyntaxHighlight
{ {
public const string Field_Static = "#8d8dc6"; public const string FIELD_STATIC = "#8d8dc6";
public const string Field_Instance = "#c266ff"; public const string FIELD_INSTANCE = "#c266ff";
public const string Method_Static = "#b55b02"; public const string METHOD_STATIC = "#b55b02";
public const string Method_Instance = "#ff8000"; public const string METHOD_INSTANCE = "#ff8000";
public const string Prop_Static = "#588075"; public const string PROP_STATIC = "#588075";
public const string Prop_Instance = "#55a38e"; public const string PROP_INSTANCE = "#55a38e";
public const string Class_Static = "#3a8d71"; public const string CLASS_STATIC = "#3a8d71";
public const string Class_Instance = "#2df7b2"; public const string CLASS_INSTANCE = "#2df7b2";
public const string Local = "#a6e9e9"; public const string CLASS_STRUCT = "#0fba3a";
public const string StructGreen = "#0fba3a"; public const string LOCAL_ARG = "#a6e9e9";
public static string Enum = "#92c470"; public static string CONST_VAR = "#92c470";
internal static readonly Color s_silver = new Color(0.66f, 0.66f, 0.66f); internal static readonly Color s_silver = new Color(0.66f, 0.66f, 0.66f);
internal static string GetClassColor(Type type) internal static string GetClassColor(Type type)
{ {
if (type.IsAbstract && type.IsSealed) if (type.IsAbstract && type.IsSealed)
return Class_Static; return CLASS_STATIC;
else if (type.IsEnum || type.IsGenericParameter) else if (type.IsEnum || type.IsGenericParameter)
return Enum; return CONST_VAR;
else if (type.IsValueType) else if (type.IsValueType)
return StructGreen; return CLASS_STRUCT;
else else
return Class_Instance; return CLASS_INSTANCE;
} }
public static string ParseFullSyntax(Type type, bool includeNamespace, MemberInfo memberInfo = null) public static string ParseFullSyntax(Type type, bool includeNamespace, MemberInfo memberInfo = null)
@ -49,7 +49,7 @@ namespace UnityExplorer.UI
if (type.IsGenericParameter || (type.HasElementType && type.GetElementType().IsGenericParameter)) if (type.IsGenericParameter || (type.HasElementType && type.GetElementType().IsGenericParameter))
{ {
ret = $"<color={Enum}>{type.Name}</color>"; ret = $"<color={CONST_VAR}>{type.Name}</color>";
} }
else else
{ {
@ -134,7 +134,7 @@ namespace UnityExplorer.UI
if (allGeneric) if (allGeneric)
{ {
args += $"<color={Enum}>{arg.Name}</color>"; args += $"<color={CONST_VAR}>{arg.Name}</color>";
continue; continue;
} }
@ -153,30 +153,30 @@ namespace UnityExplorer.UI
if (fi.IsStatic) if (fi.IsStatic)
{ {
isStatic = true; isStatic = true;
memberColor = Field_Static; memberColor = FIELD_STATIC;
} }
else else
memberColor = Field_Instance; memberColor = FIELD_INSTANCE;
} }
else if (memberInfo is MethodInfo mi) else if (memberInfo is MethodInfo mi)
{ {
if (mi.IsStatic) if (mi.IsStatic)
{ {
isStatic = true; isStatic = true;
memberColor = Method_Static; memberColor = METHOD_STATIC;
} }
else else
memberColor = Method_Instance; memberColor = METHOD_INSTANCE;
} }
else if (memberInfo is PropertyInfo pi) else if (memberInfo is PropertyInfo pi)
{ {
if (pi.GetAccessors(true)[0].IsStatic) if (pi.GetAccessors(true)[0].IsStatic)
{ {
isStatic = true; isStatic = true;
memberColor = Prop_Static; memberColor = PROP_STATIC;
} }
else else
memberColor = Prop_Instance; memberColor = PROP_INSTANCE;
} }
return memberColor; return memberColor;
} }