Beispiel #1
0
        // ~~~~~~~~~~~ Add Hooks window ~~~~~~~~~~~

        public void OnClassSelectedForHooks(string typeFullName)
        {
            var type = ReflectionUtility.GetTypeByName(typeFullName);

            if (type == null)
            {
                ExplorerCore.LogWarning($"Could not find any type by name {typeFullName}!");
                return;
            }

            Panel.SetAddHooksLabelType(SignatureHighlighter.Parse(type, true));

            Panel.ResetMethodFilter();
            filteredEligableMethods.Clear();
            currentAddEligableMethods.Clear();
            foreach (var method in type.GetMethods(ReflectionUtility.FLAGS))
            {
                if (method.IsGenericMethod || UERuntimeHelper.IsBlacklisted(method))
                {
                    continue;
                }
                currentAddEligableMethods.Add(method);
                filteredEligableMethods.Add(method);
            }

            isAddingMethods = true;
            Panel.SetPage(HookManagerPanel.Pages.ClassMethodSelector);
            Panel.AddHooksScrollPool.Refresh(true, true);
        }
        static void TryCacheMember(
            MemberInfo member,
            IList list,
            HashSet <string> cachedSigs,
            Type declaringType,
            ReflectionInspector inspector,
            bool ignorePropertyMethodInfos = true)
        {
            try
            {
                if (UERuntimeHelper.IsBlacklisted(member))
                {
                    return;
                }

                string sig = member switch
                {
                    MethodBase mb => mb.FullDescription(),
                    PropertyInfo or FieldInfo => $"{member.DeclaringType.FullDescription()}.{member.Name}",
                       _ => throw new NotImplementedException(),
                };

                if (cachedSigs.Contains(sig))
                {
                    return;
                }

                // ExplorerCore.Log($"Trying to cache member {sig}... ({member.MemberType})");

                CacheMember cached;
                Type        returnType;

                switch (member.MemberType)
                {
                case MemberTypes.Constructor:
                {
                    var ci = member as ConstructorInfo;
                    cached     = new CacheConstructor(ci);
                    returnType = ci.DeclaringType;
                }
                break;

                case MemberTypes.Method:
                {
                    var mi = member as MethodInfo;
                    if (ignorePropertyMethodInfos &&
                        (mi.Name.StartsWith("get_") || mi.Name.StartsWith("set_")))
                    {
                        return;
                    }

                    cached     = new CacheMethod(mi);
                    returnType = mi.ReturnType;
                    break;
                }

                case MemberTypes.Property:
                {
                    var pi = member as PropertyInfo;

                    if (!pi.CanRead && pi.CanWrite)
                    {
                        // write-only property, cache the set method instead.
                        var setMethod = pi.GetSetMethod(true);
                        if (setMethod != null)
                        {
                            TryCacheMember(setMethod, list, cachedSigs, declaringType, inspector, false);
                        }
                        return;
                    }

                    cached     = new CacheProperty(pi);
                    returnType = pi.PropertyType;
                    break;
                }

                case MemberTypes.Field:
                {
                    var fi = member as FieldInfo;
                    cached     = new CacheField(fi);
                    returnType = fi.FieldType;
                    break;
                }

                default:
                    throw new NotImplementedException();
                }

                cachedSigs.Add(sig);

                cached.SetFallbackType(returnType);
                cached.SetInspectorOwner(inspector, member);

                list.Add(cached);
            }
            catch (Exception e)
            {
                ExplorerCore.LogWarning($"Exception caching member {member.DeclaringType.FullName}.{member.Name}!");
                ExplorerCore.Log(e.ToString());
            }
        }