Exemple #1
0
 /// <summary>
 /// Find an existing package by name or create it if it doesn't exist
 /// </summary>
 /// <param name="outer">The Outer object to search inside</param>
 /// <param name="packageName"></param>
 /// <returns>The existing package or a newly created one</returns>
 public static UPackage CreatePackage(ObjectOuter outer, string packageName)
 {
     using (FStringUnsafe packageNameUnsafe = new FStringUnsafe(packageName))
     {
         return(GCHelper.Find <UPackage>(Native_UObjectGlobals.CreatePackage(outer.Address, ref packageNameUnsafe.Array)));
     }
 }
Exemple #2
0
        /// <summary>
        /// Create a unique name by combining a base name and an arbitrary number string.
        /// The object name returned is guaranteed not to exist.
        /// </summary>
        /// <param name="outer">the outer for the object that needs to be named</param>
        /// <param name="unrealClass">the class for the object</param>
        /// <param name="baseName">optional base name to use when generating the unique object name; if not specified, the class's name is used</param>
        /// <returns>name is the form BaseName_##, where ## is the number of objects of this
        /// type that have been created since the last time the class was garbage collected.</returns>
        public static FName MakeUniqueObjectName(ObjectOuter outer, UClass unrealClass, FName baseName = default(FName))
        {
            FName result;

            Native_UObjectGlobals.MakeUniqueObjectName(outer.Address,
                                                       unrealClass == null ? IntPtr.Zero : unrealClass.Address,
                                                       ref baseName, out result);
            return(result);
        }
Exemple #3
0
 /// <summary>
 /// Load a class object.
 /// </summary>
 public static UClass LoadClass(UClass baseClass, ObjectOuter outer, string name, string filename = null, ELoadFlags loadFlags = ELoadFlags.None)
 {
     using (FStringUnsafe nameUnsafe = new FStringUnsafe(name))
         using (FStringUnsafe filenameUnsafe = new FStringUnsafe(filename))
         {
             return(GCHelper.Find <UClass>(Native_UObjectGlobals.StaticLoadClass(
                                               baseClass.Address, outer.Address, ref nameUnsafe.Array, ref filenameUnsafe.Array, loadFlags, IntPtr.Zero)));
         }
 }
Exemple #4
0
 /// <summary>
 /// Constructs a gameplay object
 /// </summary>
 /// <typeparam name="T">the object type</typeparam>
 /// <param name="outer">the outer for the new object.  If not specified, object will be created in the transient package.</param>
 /// <param name="name">the name for the new object.  If not specified, the object will be given a transient name via MakeUniqueObjectName</param>
 /// <param name="flags">the object flags to apply to the new object</param>
 /// <param name="template">the object to use for initializing the new object.  If not specified, the class's default object will be used</param>
 /// <param name="copyTransientsFromClassDefaults">if true, copy transient from the class defaults instead of the pass in archetype ptr (often these are the same)</param>
 /// <param name="instanceGraph">contains the mappings of instanced objects and components to their templates</param>
 /// <returns>a pointer of type T to a new object of the specified class</returns>
 public static T NewObject <T>(
     ObjectOuter outer,
     FName name         = default(FName),
     EObjectFlags flags = EObjectFlags.NoFlags,
     UObject template   = null,
     bool copyTransientsFromClassDefaults = false,
     IntPtr instanceGraph = default(IntPtr)) where T : UObject
 {
     return(NewObject <T>(false, outer, UClass.GetClass <T>(), name, flags, template, copyTransientsFromClassDefaults, instanceGraph));
 }
Exemple #5
0
        /// <summary>
        /// Create a new instance of an object or replace an existing object.  If both an Outer and Name are specified, and there is an object already in memory with the same Class, Outer, and Name, the
        /// existing object will be destructed, and the new object will be created in its place.
        /// </summary>
        /// <param name="unrealClass">the class of the object to create</param>
        /// <param name="outer">the object to create this object within (the Outer property for the new object will be set to the value specified here).</param>
        /// <param name="name">the name to give the new object. If no value (NAME_None) is specified, the object will be given a unique name in the form of ClassName_#.</param>
        /// <param name="outReusedSubobject">flag indicating if the object is a subobject that has already been created (in which case further initialization is not necessary).</param>
        /// <param name="setFlags">the ObjectFlags to assign to the new object. some flags can affect the behavior of constructing the object.</param>
        /// <param name="internalSetFlags">the InternalObjectFlags to assign to the new object. some flags can affect the behavior of constructing the object.</param>
        /// <param name="canReuseSubobjects">if set to true, SAO will not attempt to destroy a subobject if it already exists in memory.</param>
        /// <returns>a pointer to a fully initialized object of the specified class.</returns>
        public static UObject StaticAllocateObject(UClass unrealClass, ObjectOuter outer, FName name, out bool outReusedSubobject,
                                                   EObjectFlags setFlags, EInternalObjectFlags internalSetFlags, bool canReuseSubobjects = false)
        {
            csbool  outReusedSubobjectTemp;
            UObject result = GCHelper.Find(Native_UObjectGlobals.StaticAllocateObject(
                                               unrealClass == null ? IntPtr.Zero : unrealClass.Address,
                                               outer.Address, ref name, setFlags, internalSetFlags, canReuseSubobjects, out outReusedSubobjectTemp));

            outReusedSubobject = outReusedSubobjectTemp;
            return(result);
        }
Exemple #6
0
        /// <summary>
        /// Find an object without asserting on GIsSavingPackage or IsGarbageCollecting()
        /// </summary>
        public static T FindObjectSafe <T>(ObjectOuter outer, string name, bool exactClass = false) where T : UObject
        {
            UClass unrealClass = UClass.GetClass <T>();

            using (FStringUnsafe nameUnsafe = new FStringUnsafe(name))
            {
                return(GCHelper.Find <T>(Native_UObjectGlobals.StaticFindObjectSafe(
                                             unrealClass == null ? IntPtr.Zero : unrealClass.Address,
                                             outer.Address, ref nameUnsafe.Array, exactClass)));
            }
        }
Exemple #7
0
        /// <summary>
        /// Load a class object.
        /// </summary>
        public static UClass LoadClass <T>(ObjectOuter outer, string name, string filename, ELoadFlags loadFlags = ELoadFlags.None)
        {
            UClass unrealClass = UClass.GetClass <T>();

            using (FStringUnsafe nameUnsafe = new FStringUnsafe(name))
                using (FStringUnsafe filenameUnsafe = new FStringUnsafe(filename))
                {
                    return(GCHelper.Find <UClass>(Native_UObjectGlobals.StaticLoadClass(
                                                      unrealClass == null ? IntPtr.Zero : unrealClass.Address,
                                                      outer.Address, ref nameUnsafe.Array, ref filenameUnsafe.Array, loadFlags, IntPtr.Zero)));
                }
        }
Exemple #8
0
        /// <summary>
        /// Find an optional object, relies on the name being unqualified
        /// </summary>
        public static T FindObjectFast <T>(
            ObjectOuter outer,
            FName name,
            bool exactClass             = false,
            bool anyPackage             = false,
            EObjectFlags exclusiveFlags = EObjectFlags.NoFlags,
            EInternalObjectFlags exclusiveInternalFlags = EInternalObjectFlags.None) where T : UObject
        {
            UClass unrealClass = UClass.GetClass <T>();

            return(GCHelper.Find <T>(Native_UObjectGlobals.StaticFindObjectFast(
                                         unrealClass == null ? IntPtr.Zero : unrealClass.Address,
                                         outer.Address, ref name, exactClass, anyPackage, exclusiveFlags, exclusiveInternalFlags)));
        }
Exemple #9
0
        private static T NewObject <T>(
            bool checkClass,
            ObjectOuter outer,
            UClass unrealClass,
            FName name         = default(FName),
            EObjectFlags flags = EObjectFlags.NoFlags,
            UObject template   = null,
            bool copyTransientsFromClassDefaults = false,
            IntPtr instanceGraph = default(IntPtr)) where T : UObject
        {
            if (unrealClass == null)
            {
                return(null);
            }

            if (!outer.IsAnyPackage && outer.Object == null)
            {
                outer.Object = GetTransientPackage();
            }

            if (name == FName.None)
            {
                FObjectInitializer.AssertIfInConstructor(outer.Object);
            }

            if (checkClass)
            {
                // DO_CHECK
                // Class was specified explicitly, so needs to be validated
                if (Native_UObjectGlobals.CheckIsClassChildOf_Internal != null)
                {
                    UClass parentClass = UClass.GetClass <T>();
                    Native_UObjectGlobals.CheckIsClassChildOf_Internal(
                        parentClass == null ? IntPtr.Zero : parentClass.Address,
                        unrealClass == null ? IntPtr.Zero : unrealClass.Address);
                }
            }

            return(GCHelper.Find <T>(Native_UObjectGlobals.StaticConstructObject_Internal(
                                         unrealClass == null ? IntPtr.Zero : unrealClass.Address,
                                         outer.Address, ref name, flags, EInternalObjectFlags.None,
                                         template == null ? IntPtr.Zero : template.Address,
                                         copyTransientsFromClassDefaults,
                                         instanceGraph)));
        }
Exemple #10
0
 /// <summary>
 /// Creates a copy of SourceObject using the Outer and Name specified, as well as copies of all objects contained by SourceObject.
 /// Any objects referenced by SourceOuter or RootObject and contained by SourceOuter are also copied, maintaining their name relative to SourceOuter.  Any
 /// references to objects that are duplicated are automatically replaced with the copy of the object.
 /// </summary>
 /// <typeparam name="T">the object type</typeparam>
 /// <param name="sourceObject">the object to duplicate</param>
 /// <param name="outer">the object to use as the Outer for the copy of SourceObject</param>
 /// <param name="name">the name to use for the copy of SourceObject</param>
 /// <param name="flagMask">a bitmask of EObjectFlags that should be propagated to the object copies.  The resulting object copies will only have the object flags
 /// specified copied from their source object.</param>
 /// <param name="destClass">optional class to specify for the destination object. MUST BE SERIALIZATION COMPATIBLE WITH SOURCE OBJECT!!!</param>
 /// <param name="duplicateForPIE"></param>
 /// <param name="internalFlagsMask">bitmask of EInternalObjectFlags that should be propagated to the object copies.</param>
 /// <returns></returns>
 public static T DuplicateObject <T>(
     T sourceObject,
     ObjectOuter outer,
     FName name                             = default(FName),
     EObjectFlags flagMask                  = EObjectFlags.AllFlags,
     UClass destClass                       = null,
     EDuplicateMode duplicateMode           = EDuplicateMode.Normal,
     EInternalObjectFlags internalFlagsMask = EInternalObjectFlags.AllFlags) where T : UObject
 {
     if (sourceObject != null)
     {
         if (!outer.IsAnyPackage && outer.Object == null)
         {
             outer.Object = GetTransientPackage();
         }
         return(GCHelper.Find <T>(Native_UObjectGlobals.StaticDuplicateObject(
                                      sourceObject == null ? IntPtr.Zero : sourceObject.Address,
                                      outer.Address, ref name, flagMask,
                                      destClass == null ? IntPtr.Zero : destClass.Address,
                                      duplicateMode, internalFlagsMask)));
     }
     return(null);
 }
Exemple #11
0
 /// <summary>
 /// Constructs a gameplay object
 /// </summary>
 /// <typeparam name="T">the object type</typeparam>
 /// <param name="outer">the outer for the new object.  If not specified, object will be created in the transient package.</param>
 /// <returns>a pointer of type T to a new object of the specified class</returns>
 public static T NewObject <T>(ObjectOuter outer = default(ObjectOuter)) where T : UObject
 {
     return(NewObject <T>(false, outer, UClass.GetClass <T>()));
 }