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; } }
/// <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); }
/// <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); }
/// <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); }
/// <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); }