예제 #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);
        }
예제 #2
0
        // UI Setup for type

        private void SetupUIForType()
        {
            for (int i = 0; i < CurrentInfo.Fields.Length || i <= inputFields.Count; i++)
            {
                if (i >= CurrentInfo.Fields.Length)
                {
                    if (i >= inputFields.Count)
                    {
                        break;
                    }

                    fieldRows[i].SetActive(false);
                    continue;
                }

                if (i >= inputFields.Count)
                {
                    AddEditorRow();
                }

                fieldRows[i].SetActive(true);

                string label = SignatureHighlighter.Parse(CurrentInfo.Fields[i].FieldType, false);
                label         += $" <color={SignatureHighlighter.FIELD_INSTANCE}>{CurrentInfo.Fields[i].Name}</color>:";
                labels[i].text = label;
            }
        }
예제 #3
0
        public override void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
        {
            Type ctorReturnType;

            // if is parameterless struct ctor
            if (typeForStructConstructor != null)
            {
                ctorReturnType = typeForStructConstructor;
                this.Owner     = inspector;

                // eg. Vector3.Vector3()
                this.NameLabelText = SignatureHighlighter.Parse(typeForStructConstructor, false);
                NameLabelText     += $".{NameLabelText}()";

                this.NameForFiltering = SignatureHighlighter.RemoveHighlighting(NameLabelText);
                this.NameLabelTextRaw = NameForFiltering;
                return;
            }
            else
            {
                base.SetInspectorOwner(inspector, member);

                Arguments      = CtorInfo.GetParameters();
                ctorReturnType = CtorInfo.DeclaringType;
            }

            if (ctorReturnType.IsGenericTypeDefinition)
            {
                GenericArguments = ctorReturnType.GetGenericArguments();
            }
        }
예제 #4
0
        private void SetGenericRows()
        {
            for (int i = 0; i < genericArguments.Length || i < genericArgRows.Count; i++)
            {
                if (i >= genericArguments.Length)
                {
                    if (i >= genericArgRows.Count)
                    {
                        break;
                    }
                    else
                    {
                        // exceeded actual args, but still iterating so there must be views left, disable them
                        genericArgRows[i].SetActive(false);
                    }
                    continue;
                }

                var arg = genericArguments[i];

                if (i >= genericArgRows.Count)
                {
                    AddArgRow(i, true);
                }

                genericArgRows[i].SetActive(true);

                var autoCompleter = genericAutocompleters[i];
                autoCompleter.BaseType = arg;
                autoCompleter.CacheTypes();

                var constraints = arg.GetGenericParameterConstraints();
                autoCompleter.GenericConstraints = constraints;

                var sb = new StringBuilder($"<color={SignatureHighlighter.CONST}>{arg.Name}</color>");

                for (int j = 0; j < constraints.Length; j++)
                {
                    if (j == 0)
                    {
                        sb.Append(' ').Append('(');
                    }
                    else
                    {
                        sb.Append(',').Append(' ');
                    }

                    sb.Append(SignatureHighlighter.Parse(constraints[j], false));

                    if (j + 1 == constraints.Length)
                    {
                        sb.Append(')');
                    }
                }

                genericArgLabels[i].text = sb.ToString();
            }
        }
        // Setting target

        private void SetTarget(object target)
        {
            string prefix;

            if (StaticOnly)
            {
                Target     = null;
                TargetType = target as Type;
                prefix     = "[S]";
            }
            else
            {
                TargetType = target.GetActualType();
                prefix     = "[R]";
            }

            // Setup main labels and tab text
            currentBaseTabText = $"{prefix} {SignatureHighlighter.Parse(TargetType, false)}";
            Tab.TabText.text   = currentBaseTabText;
            NameText.text      = SignatureHighlighter.Parse(TargetType, true);

            string asmText;

            if (TargetType.Assembly is AssemblyBuilder || string.IsNullOrEmpty(TargetType.Assembly.Location))
            {
                asmText = $"{TargetType.Assembly.GetName().Name} <color=grey><i>(in memory)</i></color>";
            }
            else
            {
                asmText = Path.GetFileName(TargetType.Assembly.Location);
            }
            AssemblyText.text = $"<color=grey>Assembly:</color> {asmText}";

            // unity helpers
            SetUnityTargets();

            // Get cache members

            this.members = CacheMember.GetCacheMembers(Target, TargetType, this);

            // reset filters

            this.filterInputField.Text = "";

            SetFilter("", StaticOnly ? BindingFlags.Static : BindingFlags.Instance);
            scopeFilterButtons[BindingFlags.Default].Component.gameObject.SetActive(!StaticOnly);
            scopeFilterButtons[BindingFlags.Instance].Component.gameObject.SetActive(!StaticOnly);

            foreach (var toggle in memberTypeToggles)
            {
                toggle.isOn = true;
            }

            refreshWanted = true;
        }
예제 #6
0
        protected virtual void SetValueState(CacheObjectCell cell, ValueStateArgs args)
        {
            // main value label
            if (args.valueActive)
            {
                cell.ValueLabel.text            = ValueLabelText;
                cell.ValueLabel.supportRichText = args.valueRichText;
                cell.ValueLabel.color           = args.valueColor;
            }
            else
            {
                cell.ValueLabel.text = "";
            }

            // Type label (for primitives)
            cell.TypeLabel.gameObject.SetActive(args.typeLabelActive);
            if (args.typeLabelActive)
            {
                cell.TypeLabel.text = SignatureHighlighter.Parse(LastValueType, false);
            }

            // toggle for bools
            cell.Toggle.gameObject.SetActive(args.toggleActive);
            if (args.toggleActive)
            {
                cell.Toggle.interactable = CanWrite;
                cell.Toggle.isOn         = (bool)Value;
                cell.ToggleText.text     = Value.ToString();
            }

            // inputfield for numbers
            cell.InputField.UIRoot.SetActive(args.inputActive);
            if (args.inputActive)
            {
                cell.InputField.Text = ParseUtility.ToStringForInput(Value, LastValueType);
                cell.InputField.Component.readOnly = !CanWrite;
            }

            // apply for bool and numbers
            cell.ApplyButton.Component.gameObject.SetActive(args.applyActive);

            // Inspect button only if last value not null.
            if (cell.InspectButton != null)
            {
                cell.InspectButton.Component.gameObject.SetActive(args.inspectActive && !LastValueWasNull);
            }

            // allow IValue for null strings though
            cell.SubContentButton.Component.gameObject.SetActive(args.subContentButtonActive && (!LastValueWasNull || State == ValueState.String));
        }
예제 #7
0
        void AddSuggestion(Type type)
        {
            if (suggestedNames.Contains(type.FullName))
            {
                return;
            }
            suggestedNames.Add(type.FullName);

            if (!sharedTypeToLabel.ContainsKey(type.FullName))
            {
                sharedTypeToLabel.Add(type.FullName, SignatureHighlighter.Parse(type, true));
            }

            suggestions.Add(new Suggestion(sharedTypeToLabel[type.FullName], type.FullName));
        }
예제 #8
0
        private void SetNormalArgRows()
        {
            for (int i = 0; i < arguments.Length || i < argRows.Count; i++)
            {
                if (i >= arguments.Length)
                {
                    if (i >= argRows.Count)
                    {
                        break;
                    }
                    else
                    {
                        // exceeded actual args, but still iterating so there must be views left, disable them
                        argRows[i].SetActive(false);
                    }
                    continue;
                }

                var arg = arguments[i];


                if (i >= argRows.Count)
                {
                    AddArgRow(i, false);
                }

                argRows[i].SetActive(true);
                argLabels[i].text = $"{SignatureHighlighter.Parse(arg.ParameterType, false)} <color={SignatureHighlighter.LOCAL_ARG}>{arg.Name}</color>";
                if (arg.ParameterType == typeof(string))
                {
                    argInputFields[i].PlaceholderText.text = "";
                }
                else
                {
                    var elemType = arg.ParameterType;
                    if (elemType.IsByRef)
                    {
                        elemType = elemType.GetElementType();
                    }
                    argInputFields[i].PlaceholderText.text = $"eg. {ParseUtility.GetExampleInput(elemType)}";
                }
            }
        }
예제 #9
0
        public void SetCell(ButtonCell cell, int index)
        {
            if (!cachedCellTexts.ContainsKey(index))
            {
                string text;
                if (m_context == SearchContext.StaticClass)
                {
                    text = SignatureHighlighter.Parse(currentResults[index] as Type, true);
                }
                else
                {
                    text = ToStringUtility.ToStringWithType(currentResults[index], currentResults[index]?.GetActualType());
                }

                cachedCellTexts.Add(index, text);
            }

            cell.Button.ButtonText.text = cachedCellTexts[index];
        }
예제 #10
0
        public void SetKey(object key)
        {
            this.DictKey      = key;
            this.DisplayedKey = key.TryCast();

            var type = DisplayedKey.GetType();

            if (ParseUtility.CanParse(type))
            {
                KeyInputWanted   = true;
                KeyInputText     = ParseUtility.ToStringForInput(DisplayedKey, type);
                KeyInputTypeText = SignatureHighlighter.Parse(type, false);
            }
            else
            {
                KeyInputWanted = false;
                InspectWanted  = type != typeof(bool) && !type.IsEnum;
                KeyLabelText   = ToStringUtility.ToStringWithType(DisplayedKey, type, true);
            }
        }
        public override void SetValue(object value)
        {
            if (value == null)
            {
                // should never be null
                ClearAndRelease();
                return;
            }
            else
            {
                var type = value.GetActualType();
                ReflectionUtility.TryGetEntryTypes(type, out KeysType, out ValuesType);

                CacheEntries(value);

                TopLabel.text = $"[{cachedEntries.Count}] {SignatureHighlighter.Parse(type, false)}";
            }

            this.DictScrollPool.Refresh(true, false);
        }
예제 #12
0
        // Called from ButtonListHandler.SetCell, will be valid
        private void SetComponentCell(ComponentCell cell, int index)
        {
            var entries = GetEntries();

            cell.Enable();

            var comp = entries[index];
            var type = comp.GetActualType();

            if (!compToStringCache.ContainsKey(type.AssemblyQualifiedName))
            {
                compToStringCache.Add(type.AssemblyQualifiedName, SignatureHighlighter.Parse(type, true));
            }

            cell.Button.ButtonText.text = compToStringCache[type.AssemblyQualifiedName];

            if (typeof(Behaviour).IsAssignableFrom(type))
            {
                cell.BehaviourToggle.interactable = true;
                cell.BehaviourToggle.Set(comp.TryCast <Behaviour>().enabled, false);
                cell.BehaviourToggle.graphic.color = new Color(0.8f, 1, 0.8f, 0.3f);
            }
            else
            {
                cell.BehaviourToggle.interactable = false;
                cell.BehaviourToggle.Set(true, false);
                //RuntimeProvider.Instance.SetColorBlock(cell.BehaviourToggle,)
                cell.BehaviourToggle.graphic.color = new Color(0.2f, 0.2f, 0.2f);
            }

            // if component is the first index it must be the transform, dont show Destroy button for it.
            if (index == 0 && cell.DestroyButton.Component.gameObject.activeSelf)
            {
                cell.DestroyButton.Component.gameObject.SetActive(false);
            }
            else if (index > 0 && !cell.DestroyButton.Component.gameObject.activeSelf)
            {
                cell.DestroyButton.Component.gameObject.SetActive(true);
            }
        }
예제 #13
0
        // Setting the List value itself to this model
        public override void SetValue(object value)
        {
            if (value == null)
            {
                // should never be null
                if (cachedEntries.Any())
                {
                    ClearAndRelease();
                }
            }
            else
            {
                var type = value.GetActualType();
                ReflectionUtility.TryGetEntryType(type, out EntryType);

                CacheEntries(value);

                TopLabel.text = $"[{cachedEntries.Count}] {SignatureHighlighter.Parse(type, false)}";
            }

            //this.ScrollPoolLayout.minHeight = Math.Min(400f, 35f * values.Count);
            this.ListScrollPool.Refresh(true, false);
        }
예제 #14
0
        public void OnBorrowed(EvaluateWidget evaluator, Type genericConstraint)
        {
            this.evaluator   = evaluator;
            this.genericType = genericConstraint;

            typeCompleter.Enabled  = true;
            typeCompleter.BaseType = genericType;
            typeCompleter.CacheTypes();

            var constraints = genericType.GetGenericParameterConstraints();

            typeCompleter.GenericConstraints = constraints;

            var sb = new StringBuilder($"<color={SignatureHighlighter.CONST}>{genericType.Name}</color>");

            for (int j = 0; j < constraints.Length; j++)
            {
                if (j == 0)
                {
                    sb.Append(' ').Append('(');
                }
                else
                {
                    sb.Append(',').Append(' ');
                }

                sb.Append(SignatureHighlighter.Parse(constraints[j], false));

                if (j + 1 == constraints.Length)
                {
                    sb.Append(')');
                }
            }

            argNameLabel.text = sb.ToString();
        }
예제 #15
0
 public virtual void SetInspectorOwner(ReflectionInspector inspector, MemberInfo member)
 {
     this.Owner            = inspector;
     this.NameLabelText    = SignatureHighlighter.Parse(member.DeclaringType, false, member);
     this.NameForFiltering = $"{member.DeclaringType.Name}.{member.Name}";
 }
예제 #16
0
        public void OnBorrowed(EvaluateWidget evaluator, ParameterInfo paramInfo)
        {
            this.evaluator = evaluator;
            this.paramInfo = paramInfo;

            this.paramType = paramInfo.ParameterType;
            if (paramType.IsByRef)
            {
                paramType = paramType.GetElementType();
            }

            this.argNameLabel.text =
                $"{SignatureHighlighter.Parse(paramType, false)} <color={SignatureHighlighter.LOCAL_ARG}>{paramInfo.Name}</color>";

            if (ParseUtility.CanParse(paramType) || typeof(Type).IsAssignableFrom(paramType))
            {
                usingBasicLabel = false;

                this.inputField.Component.gameObject.SetActive(true);
                this.basicLabelHolder.SetActive(false);
                this.typeCompleter.Enabled = typeof(Type).IsAssignableFrom(paramType);
                this.enumCompleter.Enabled = paramType.IsEnum;
                this.enumHelperButton.Component.gameObject.SetActive(paramType.IsEnum);

                if (!typeCompleter.Enabled)
                {
                    if (paramType == typeof(string))
                    {
                        inputField.PlaceholderText.text = "...";
                    }
                    else
                    {
                        inputField.PlaceholderText.text = $"eg. {ParseUtility.GetExampleInput(paramType)}";
                    }
                }
                else
                {
                    inputField.PlaceholderText.text = "Enter a Type name...";
                    this.typeCompleter.BaseType     = typeof(object);
                    this.typeCompleter.CacheTypes();
                }

                if (enumCompleter.Enabled)
                {
                    enumCompleter.EnumType = paramType;
                    enumCompleter.CacheEnumValues();
                }
            }
            else
            {
                // non-parsable, and not a Type
                usingBasicLabel = true;

                this.inputField.Component.gameObject.SetActive(false);
                this.basicLabelHolder.SetActive(true);
                this.typeCompleter.Enabled = false;
                this.enumCompleter.Enabled = false;
                this.enumHelperButton.Component.gameObject.SetActive(false);

                SetDisplayedValueFromPaste();
            }
        }
예제 #17
0
        protected string GetValueLabel()
        {
            string label = "";

            switch (State)
            {
            case ValueState.NotEvaluated:
                return($"<i>{NOT_YET_EVAL} ({SignatureHighlighter.Parse(FallbackType, true)})</i>");

            case ValueState.Exception:
                return($"<i><color=red>{LastException.ReflectionExToString()}</color></i>");

            // bool and number dont want the label for the value at all
            case ValueState.Boolean:
            case ValueState.Number:
                return(null);

            // and valuestruct also doesnt want it if we can parse it
            case ValueState.ValueStruct:
                if (ParseUtility.CanParse(LastValueType))
                {
                    return(null);
                }
                break;

            // string wants it trimmed to max 200 chars
            case ValueState.String:
                if (!LastValueWasNull)
                {
                    return($"\"{ToStringUtility.PruneString(Value as string, 200, 5)}\"");
                }
                break;

            // try to prefix the count of the collection for lists and dicts
            case ValueState.Collection:
                if (!LastValueWasNull)
                {
                    if (Value is IList iList)
                    {
                        label = $"[{iList.Count}] ";
                    }
                    else if (Value is ICollection iCol)
                    {
                        label = $"[{iCol.Count}] ";
                    }
                    else
                    {
                        label = "[?] ";
                    }
                }
                break;

            case ValueState.Dictionary:
                if (!LastValueWasNull)
                {
                    if (Value is IDictionary iDict)
                    {
                        label = $"[{iDict.Count}] ";
                    }
                    else
                    {
                        label = "[?] ";
                    }
                }
                break;
            }

            // Cases which dont return will append to ToStringWithType

            return(label += ToStringUtility.ToStringWithType(Value, FallbackType, true));
        }