Example #1
0
        internal static void OnUnload()
        {
            Debug.Assert(FThreading.IsInGameThread(), "Load/hotreload should be on the game thread");
            //if (!FThreading.IsInGameThread())
            //{
            //    FThreading.RunUnloader(delegate { OnUnload(); });
            //    return;
            //}

            Data        = new DataStore();
            IsUnloading = true;

            try
            {
                if (UnloadBegin != null)
                {
                    UnloadBegin();
                }
            }
            catch (Exception e)
            {
                FMessage.Log(ELogVerbosity.Error, "HotReload.UnloadBegin failed. Exception: " + Environment.NewLine + e);
            }

            Engine.FUSharpLatentAction.OnUnload();
            Engine.ManagedLatentCallbackHelper.UnregisterCallbacks();
            StaticVarManager.OnUnload();
            EngineLoop.OnUnload();
            FThreading.OnUnload();
            FTicker.OnUnload();
            IConsoleManager.OnUnload();
            ManagedUnrealTypes.OnUnload();
            GCHelper.OnUnload();

            UnbindNativeDelegates();

            IsUnloaded = true;

            try
            {
                if (UnloadEnd != null)
                {
                    UnloadEnd();
                }
            }
            catch (Exception e)
            {
                FMessage.Log(ELogVerbosity.Error, "HotReload.UnloadEnd failed. Exception: " + Environment.NewLine + e);
            }
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }
 private void Constructor(IntPtr objectInitializerPtr)
 {
     ManagedUnrealTypes.ClassConstructor(this, objectInitializerPtr);
 }
Example #7
0
 /// <summary>
 /// Returns true if the given managed type can lazily load properties/offsets/functions when the type is first
 /// accessed rather than when USharp is first initialized.
 /// </summary>
 public static bool CanLazyLoadManagedType(Type type)
 {
     return(LazyLoadingEnabled && gatheredUnrealTypes && ManagedUnrealTypes.IsTypeRegistered(type));
 }
Example #8
0
        private IntPtr CreateProperty(IntPtr outer, Type type, string propertyName, EPropertyType propertyType,
                                      EPropertyType innerPropertyType1, EPropertyType innerPropertyType2)
        {
            propertyType = ManagedUnrealTypes.GetPropertyType(type, propertyType);

            IntPtr propertyClass = ManagedUnrealTypes.GetPropertyClass(propertyType);

            if (propertyClass == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            EObjectFlags objectFlags = EObjectFlags.Public | EObjectFlags.Transient | EObjectFlags.MarkAsNative;
            IntPtr       property    = NativeReflection.NewObject(outer, propertyClass, new FName(propertyName), objectFlags);

            Native_UProperty.SetPropertyFlags(property, EPropertyFlags.BlueprintVisible | EPropertyFlags.BlueprintAssignable | EPropertyFlags.Edit);

            // Set type specific information
            switch (propertyType)
            {
            case EPropertyType.Array:
                if (!firstRun)
                {
                    Native_UArrayProperty.Set_Inner(property,
                                                    CreateProperty(property, typeof(int), propertyName, innerPropertyType1));
                }
                else
                {
                    Native_UArrayProperty.Set_Inner(property,
                                                    CreateProperty(property, type.GenericTypeArguments[0], propertyName, innerPropertyType1));
                }
                break;

            case EPropertyType.Set:
                Native_USetProperty.Set_ElementProp(property,
                                                    CreateProperty(property, type.GenericTypeArguments[0], propertyName, innerPropertyType1));
                break;

            case EPropertyType.Map:
                Native_UMapProperty.Set_KeyProp(property,
                                                CreateProperty(property, type.GenericTypeArguments[0], propertyName, innerPropertyType1));
                Native_UMapProperty.Set_ValueProp(property,
                                                  CreateProperty(property, type.GenericTypeArguments[1], propertyName, innerPropertyType2));
                break;

            case EPropertyType.Class:
                Native_UClassProperty.SetMetaClass(property, UClass.GetClass(type.GenericTypeArguments[0]).Address);
                break;

            case EPropertyType.Object:
                var v1 = ManagedUnrealTypes.GetStaticClass(type);
                var v2 = ManagedUnrealTypes.GetStaticClass(typeof(UObject));
                Native_UObjectPropertyBase.SetPropertyClass(property, v1 == IntPtr.Zero ? v2 : v1);
                break;

            case EPropertyType.LazyObject:
            case EPropertyType.WeakObject:
            case EPropertyType.SoftObject:
                Native_UObjectPropertyBase.SetPropertyClass(property, UClass.GetClass(type.GenericTypeArguments[0]).Address);
                break;

            case EPropertyType.SoftClass:
                Native_USoftClassProperty.SetMetaClass(property, UClass.GetClass(type.GenericTypeArguments[0]).Address);
                break;

            case EPropertyType.Enum:
                Native_UEnumProperty.SetEnum(property, ManagedUnrealTypes.GetEnum(type));
                break;

            case EPropertyType.Delegate:
                //Native_UDelegateProperty.Set_SignatureFunction(property, ManagedUnrealTypes.GetSignatureFunction(type));
                break;

            case EPropertyType.MulticastDelegate:
                //Native_UMulticastDelegateProperty.Set_SignatureFunction(property, ManagedUnrealTypes.GetSignatureFunction(type));
                break;
            }

            Native_UField.AddCppProperty(outer, property);

            return(property);
        }