Ejemplo n.º 1
0
        public IActionResult Modelo(string nome)
        {
            if (AllTypes.TryGetValue(nome, out Type type))
            {
                var jsonSchema = type.GetDnJsonSchema(false);
                jsonSchema.Formulario.Nome = type.GetFriendlyName();
                jsonSchema.Desabilitado    = type.GetCustomAttribute <DnDesabilitadoAttribute>(true)?.Motivo ?? "";
                jsonSchema.Propriedades.Where(x => x.Propriedade.GetCustomAttribute <DnDocAtributo>()?.Apresentacao != EnumApresentar.Ocultar).ToList()
                .ForEach(x =>
                {
                    x.Descricao = x.Descricao?.G() ?? x.Propriedade.GetCustomAttribute <DnPropriedadeJsonAtributo>(true)?.Descricao;
                    x.Link      = GetModelLink(x.Tipo);
                });

                if (type.IsNullableEnum())
                {
                    jsonSchema.Propriedades = type.GetFields().Where(x => x.Name != "value__").Select(x =>
                                                                                                      new DnPropriedadeJsonAtributo
                    {
                        NomeDaPropriedade = x.Name,
                        Nome         = (x.GetCustomAttribute <DnPropriedadeJsonAtributo>(true)?.Descricao ?? x.Name),
                        Descricao    = (x.GetCustomAttribute <DescriptionAttribute>(true)?.Description ?? x.GetCustomAttribute <DnPropriedadeJsonAtributo>(true)?.Descricao ?? x.Name).G(),
                        Formulario   = EnumTipoDeComponenteDeFormularioDeTela.Texto,
                        Tipo         = x.FieldType.BaseType,
                        Desabilitado = x.GetCustomAttribute <DnDesabilitadoAttribute>(true)?.Motivo ?? ""
                    }).ToList();
                }

                return(View(jsonSchema));
            }

            return(Content("Model not found"));
        }
Ejemplo n.º 2
0
        public Il2CppSystem.Object BoxIl2CppObject(object value)
        {
            if (value == null)
            {
                return(null);
            }

            try
            {
                var type = value.GetType();
                if (!type.IsValueType)
                {
                    return(null);
                }

                if (type.IsEnum)
                {
                    return(Il2CppSystem.Enum.Parse(Il2CppType.From(type), value.ToString()));
                }

                if (type.IsPrimitive && AllTypes.TryGetValue($"Il2Cpp{type.FullName}", out Type cppType))
                {
                    return(BoxIl2CppObject(MakeIl2CppPrimitive(cppType, value), cppType));
                }

                return(BoxIl2CppObject(value, type));
            }
            catch (Exception ex)
            {
                ExplorerCore.LogWarning("Exception in BoxIl2CppObject: " + ex);
                return(null);
            }
        }
Ejemplo n.º 3
0
        internal static string GetModelLink(Type type)
        {
            var fullName = type.GetListTypeNonNull().FullName;

            if (string.IsNullOrWhiteSpace(fullName))
            {
                return(string.Empty);
            }
            if (AllTypes.TryGetValue(type.GetListTypeNonNull().FullName, out _))
            {
                return($"/DnDoc/modelo?Nome={type.GetListTypeNonNull().FullName}");
            }
            return(string.Empty);
        }
Ejemplo n.º 4
0
        internal override Type Internal_GetActualType(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var type = obj.GetType();

            try
            {
                if (IsString(obj))
                {
                    return(typeof(string));
                }

                if (IsIl2CppPrimitive(type))
                {
                    return(il2cppPrimitivesToMono[type.FullName]);
                }

                if (obj is Il2CppSystem.Object cppObject)
                {
                    var cppType = cppObject.GetIl2CppType();

                    // check if type is injected
                    IntPtr classPtr = il2cpp_object_get_class(cppObject.Pointer);
                    if (RuntimeSpecificsStore.IsInjected(classPtr))
                    {
                        // Note: This will fail on injected subclasses.
                        // - {Namespace}.{Class}.{Subclass} would be {Namespace}.{Subclass} when injected.
                        // Not sure on solution yet.
                        return(GetTypeByName(cppType.FullName) ?? type);
                    }

                    if (AllTypes.TryGetValue(cppType.FullName, out Type primitive) && primitive.IsPrimitive)
                    {
                        return(primitive);
                    }

                    return(GetUnhollowedType(cppType) ?? type);
                }
            }
            catch (Exception ex)
            {
                ExplorerCore.LogWarning("Exception in IL2CPP GetActualType: " + ex);
            }

            return(type);
        }
Ejemplo n.º 5
0
        public static Type GetUnhollowedType(CppType cppType)
        {
            var fullname = cppType.FullName;

            if (DeobfuscatedTypes.TryGetValue(fullname, out Type deob))
            {
                return(deob);
            }

            if (fullname.StartsWith("System."))
            {
                fullname = $"Il2Cpp{fullname}";
            }

            AllTypes.TryGetValue(fullname, out Type monoType);
            return(monoType);
        }
Ejemplo n.º 6
0
        internal static bool TryGetEnumNames(string enumName, out string[] names)
        {
            if (enumName == null || !(UserDefinedTypes.TryGetValue(enumName, out Type type) || AllTypes.TryGetValue(enumName, out type)) || !type.IsEnum)
            {
                names = null;
                return(false);
            }

            names = Enum.GetNames(type).Select(name => type.Name + "." + name).ToArray();
            return(true);
        }
Ejemplo n.º 7
0
 internal static bool IsEnum(string enumName)
 {
     return(enumName != null && (UserDefinedTypes.TryGetValue(enumName, out Type type) || AllTypes.TryGetValue(enumName, out type)) &&
            type.IsEnum && Enum.GetValues(type).Length > 0);
 }