Пример #1
0
        static StructDefault()
        {
            Type type = typeof(T);

            IsStructAsClass = type.IsSubclassOf(typeof(StructAsClass));

            if (!type.IsValueType && !IsStructAsClass)
            {
                useDefaultT = true;
                return;
            }

            UUnrealTypePathAttribute pathAttribute = UnrealTypes.GetPathAttribute(type);

            if (UnrealTypes.All.TryGetValue(type, out pathAttribute) && !string.IsNullOrEmpty(pathAttribute.Path))
            {
                structPath = pathAttribute.Path;
            }

            IsStruct = !string.IsNullOrEmpty(structPath);

            if (IsStructAsClass)
            {
                // All structs as classes must be allocated on the heap and cannot use default(T)
                useDefaultT = false;
                fromNative  = MarshalingDelegateResolver <T> .FromNative;
                return;
            }

            if (!IsStruct)
            {
                useDefaultT = true;
                return;
            }

            foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly))
            {
                if (method.Name == "FromNative" && method.GetParameters().Length == 3)
                {
                    fromNative = (MarshalingDelegates <T> .FromNative)Delegate.CreateDelegate(typeof(MarshalingDelegates <T> .FromNative), method);
                    break;
                }
            }

            if (fromNative != null)
            {
                IsBlittableStruct = false;
            }
            else
            {
                IsBlittableStruct = true;
            }
        }
Пример #2
0
        private static void InitMetaData(MemberInfo member)
        {
            UUnrealTypePathAttribute pathAttribute = member.GetCustomAttribute <UUnrealTypePathAttribute>(false);

            if (pathAttribute == null || string.IsNullOrEmpty(pathAttribute.Path))
            {
                return;
            }

            Dictionary <FName, string> values = new Dictionary <FName, string>();
            var metaAttributes = member.GetCustomAttributes <UMetaAttribute>(false);

            if (metaAttributes != null)
            {
                foreach (UMetaAttribute attribute in metaAttributes)
                {
                    values[new FName(attribute.Key)] = attribute.Value;
                }
            }
            var unrealAttributes = member.GetCustomAttributes <ManagedUnrealAttributeBase>(false);

            if (unrealAttributes != null)
            {
                foreach (ManagedUnrealAttributeBase attribute in unrealAttributes)
                {
                    if (attribute.HasMetaData)
                    {
                        attribute.SetMetaData(values);
                    }
                }
            }
            if (values.Count > 0)
            {
                metaDataMap.Add(pathAttribute.Path.ToLower(), values);
            }

            MethodInfo method = member as MethodInfo;

            if (method != null)
            {
                if (method.ReturnParameter != null)
                {
                    InitMetaData(pathAttribute.Path, method.ReturnParameter);
                }

                foreach (ParameterInfo parameter in method.GetParameters())
                {
                    InitMetaData(pathAttribute.Path, parameter);
                }
            }
        }
Пример #3
0
        private static string GetInterfaceTypeName(Type interfaceType)
        {
            UUnrealTypePathAttribute pathAttribute = interfaceType.GetCustomAttribute <UUnrealTypePathAttribute>();

            if (pathAttribute != null && !string.IsNullOrEmpty(pathAttribute.Path))
            {
                return(pathAttribute.Path);
            }
            else
            {
                // Failed to get the attribute... throw an exception?
                return(interfaceType.Name);
            }
        }
Пример #4
0
        /// <summary>
        /// Gets the address of the UEnum for the given enum type
        /// </summary>
        /// <param name="type">The type of the enum</param>
        /// <returns>The address of the UEnum for the given type</returns>
        public static IntPtr GetEnumAddress(Type type)
        {
            UUnrealTypePathAttribute pathAttribute = UnrealTypes.GetPathAttribute(type);

            if (pathAttribute != null)
            {
                if (pathAttribute.IsManagedType)
                {
                    return(ManagedUnrealTypes.GetEnumAddress(type));
                }
                else
                {
                    return(GetEnumAddress(pathAttribute.Path));
                }
            }
            return(IntPtr.Zero);
        }
Пример #5
0
        /// <summary>
        /// Gets the address of the UFunction for the given delegate type
        /// </summary>
        /// <param name="type">The type of the delegate</param>
        /// <returns>The address of the UFunction for the given type</returns>
        public static IntPtr GetDelegateSignatureAddress(Type type)
        {
            UUnrealTypePathAttribute pathAttribute = UnrealTypes.GetPathAttribute(type);

            if (pathAttribute != null)
            {
                if (pathAttribute.IsManagedType)
                {
                    // TODO: Support dynamic loading of managed types
                    return(ManagedUnrealTypes.GetDelegateSignatureAddress(type));
                }
                else
                {
                    return(GetFunctionAddress(pathAttribute.Path));
                }
            }
            return(IntPtr.Zero);
        }
Пример #6
0
        /// <summary>
        /// Loads the address of the UScriptStruct for the given struct type
        /// </summary>
        /// <param name="type">The type of the struct</param>
        /// <returns>The address of the UScriptStruct for the given type</returns>
        public static IntPtr LoadStructAddress(Type type)
        {
            UUnrealTypePathAttribute pathAttribute = UnrealTypes.GetPathAttribute(type);

            if (pathAttribute != null)
            {
                if (pathAttribute.IsManagedType)
                {
                    // TODO: Support dynamic loading of managed types
                    return(ManagedUnrealTypes.GetStructAddress(type));
                }
                else
                {
                    return(LoadStructAddress(pathAttribute.Path));
                }
            }
            return(IntPtr.Zero);
        }
Пример #7
0
        /// <summary>
        /// Gets the UClass address for the given UObject derived type
        /// </summary>
        /// <param name="type">The UObject derived type</param>
        /// <returns>The address of the UClass for the given type</returns>
        public static IntPtr GetClassAddress(Type type)
        {
            UUnrealTypePathAttribute pathAttribute = UnrealTypes.GetPathAttribute(type);

            if (pathAttribute != null)
            {
                if (pathAttribute.IsManagedType)
                {
                    return(ManagedUnrealTypes.GetClassAddress(type));
                }
                else
                {
                    UClass unrealClass = GetClass(type);
                    if (unrealClass != null)
                    {
                        return(unrealClass.Address);
                    }
                }
            }
            return(IntPtr.Zero);
        }
Пример #8
0
        private static void LoadInternal(Assembly thisAssembly, Assembly assembly)
        {
            if (processedAssemblies.Contains(assembly))
            {
                return;
            }
            processedAssemblies.Add(assembly);

            bool referencesThisAssembly = false;

            if (assembly == thisAssembly)
            {
                referencesThisAssembly = true;
            }
            else
            {
                foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies())
                {
                    if (assemblyName.FullName == thisAssembly.FullName)
                    {
                        referencesThisAssembly = true;
                        break;
                    }
                }
            }
            if (!referencesThisAssembly)
            {
                return;
            }

            List <Type> types = new List <Type>();
            Dictionary <Type, UMetaPathAttribute>  nativeTypes  = new Dictionary <Type, UMetaPathAttribute>();
            Dictionary <Type, USharpPathAttribute> managedTypes = new Dictionary <Type, USharpPathAttribute>();
            Type assemblyModuleInfoType = null;

            foreach (Type type in assembly.GetTypes())
            {
                UUnrealTypePathAttribute pathAttribute = type.GetCustomAttribute <UUnrealTypePathAttribute>(false);
                if (pathAttribute != null && !string.IsNullOrEmpty(pathAttribute.Path))
                {
                    USharpPathAttribute sharpPathAttribute = pathAttribute as USharpPathAttribute;
                    if (sharpPathAttribute != null)
                    {
                        AllByPath[pathAttribute.Path]     = type;
                        ManagedByPath[pathAttribute.Path] = type;

                        All[type]     = sharpPathAttribute;
                        Managed[type] = sharpPathAttribute;

                        types.Add(type);
                        managedTypes[type] = sharpPathAttribute;
                    }
                    else
                    {
                        UMetaPathAttribute metaPathAttribute = pathAttribute as UMetaPathAttribute;
                        if (metaPathAttribute != null)
                        {
                            AllByPath[pathAttribute.Path]    = type;
                            NativeByPath[pathAttribute.Path] = type;

                            All[type]    = metaPathAttribute;
                            Native[type] = metaPathAttribute;

                            types.Add(type);
                            nativeTypes[type] = metaPathAttribute;
                        }
                    }
                }

                if (typeof(ISerializedManagedUnrealModuleInfo).IsAssignableFrom(type) &&
                    type != typeof(ISerializedManagedUnrealModuleInfo))
                {
                    assemblyModuleInfoType = type;
                }
            }

            if (types.Count > 0)
            {
                Assemblies[assembly]             = types;
                AssembliesManagedTypes[assembly] = managedTypes;
                AssembliesNativeTypes[assembly]  = nativeTypes;
                if (assemblyModuleInfoType != null)
                {
                    AssemblySerializedModuleInfo[assembly] = assemblyModuleInfoType;
                }
            }
        }