Beispiel #1
0
 public TArrayReadOnlyMarshaler(int length, UFieldAddress arrayProperty,
                                MarshalingDelegates <T> .FromNative fromNative, MarshalingDelegates <T> .ToNative toNative)
 {
     property        = arrayProperty;
     wrappers        = new TArrayReadOnly <T> [length];
     innerFromNative = fromNative;
 }
Beispiel #2
0
 public TSetReadOnlyMarshaler(int length, UFieldAddress setProperty,
                              MarshalingDelegates <T> .FromNative fromNative, MarshalingDelegates <T> .ToNative toNative)
 {
     property          = setProperty;
     wrappers          = new TSetReadOnly <T> [length];
     elementFromNative = fromNative;
 }
Beispiel #3
0
 public UnrealArrayReadWriteMarshaler(int length, IntPtr nativeProperty, MarshalingDelegates <T> .ToNative toNative, MarshalingDelegates <T> .FromNative fromNative)
 {
     NativeProperty      = nativeProperty;
     Wrappers            = new UnrealArrayReadWrite <T> [length];
     InnerTypeFromNative = fromNative;
     InnerTypeToNative   = toNative;
 }
Beispiel #4
0
 public TSetCopyMarshaler(int length, UFieldAddress setProperty,
                          MarshalingDelegates <T> .FromNative fromNative, MarshalingDelegates <T> .ToNative toNative)
 {
     property          = setProperty;
     helper            = new FScriptSetHelper(property.Address);
     elementFromNative = fromNative;
     elementToNative   = toNative;
 }
Beispiel #5
0
 public UnrealArrayBase(UnrealObject ownerObject, IntPtr nativeUnrealProperty, IntPtr nativeBuffer, MarshalingDelegates <T> .ToNative toNative, MarshalingDelegates <T> .FromNative fromNative)
 {
     OwnerObject          = ownerObject;
     NativeUnrealProperty = nativeUnrealProperty;
     NativeBuffer_        = nativeBuffer;
     FromNative           = fromNative;
     ToNative             = toNative;
 }
Beispiel #6
0
 public TArrayCopyMarshaler(int length, UFieldAddress arrayProperty,
                            MarshalingDelegates <T> .FromNative fromNative, MarshalingDelegates <T> .ToNative toNative)
 {
     property        = arrayProperty;
     helper          = new FScriptArrayHelper(property.Address);
     innerFromNative = fromNative;
     innerToNative   = toNative;
 }
Beispiel #7
0
 public TSetReadWriteMarshaler(int length, UFieldAddress setProperty,
                               MarshalingDelegates <T> .FromNative fromNative, MarshalingDelegates <T> .ToNative toNative)
 {
     property          = setProperty;
     helper            = new FScriptSetHelper(property.Address);
     wrappers          = new TSetReadWrite <T> [length];
     elementFromNative = fromNative;
     elementToNative   = toNative;
 }
Beispiel #8
0
 public TArrayReadWriteMarshaler(int length, UFieldAddress arrayProperty,
                                 MarshalingDelegates <T> .FromNative fromNative, MarshalingDelegates <T> .ToNative toNative)
 {
     property        = arrayProperty;
     helper          = new FScriptArrayHelper(property.Address);
     wrappers        = new TArrayReadWrite <T> [length];
     innerFromNative = fromNative;
     innerToNative   = toNative;
 }
Beispiel #9
0
 public TMapReadOnlyMarshaler(int length, UFieldAddress mapProperty,
                              MarshalingDelegates <TKey> .FromNative keyFromNative, MarshalingDelegates <TKey> .ToNative keyToNative,
                              MarshalingDelegates <TValue> .FromNative valueFromNative, MarshalingDelegates <TValue> .ToNative valueToNative)
 {
     property             = mapProperty;
     wrappers             = new TMapReadOnly <TKey, TValue> [length];
     this.keyFromNative   = keyFromNative;
     this.valueFromNative = valueFromNative;
 }
Beispiel #10
0
        internal static void ToNativeInternal(IntPtr nativeBuffer, int arrayIndex, IEnumerable <T> value,
                                              ref FScriptSetHelper helper, MarshalingDelegates <T> .ToNative elementToNative)
        {
            IntPtr scriptSetAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptSet)));

            helper.Set = scriptSetAddress;

            // Make sure any existing elements are properly destroyed
            helper.EmptyValues();

            if (value == null)
            {
                return;
            }

            unsafe
            {
                FScriptSet *set = (FScriptSet *)scriptSetAddress;

                IList <T> list = value as IList <T>;
                if (list != null)
                {
                    for (int i = 0; i < list.Count; ++i)
                    {
                        helper.AddElement(list[i], elementToNative);
                    }
                    return;
                }

                HashSet <T> hashSet = value as HashSet <T>;
                if (hashSet != null)
                {
                    foreach (T item in hashSet)
                    {
                        helper.AddElement(item, elementToNative);
                    }
                    return;
                }

                TSetBase <T> setBase = value as TSetBase <T>;
                if (setBase != null)
                {
                    foreach (T item in setBase)
                    {
                        helper.AddElement(item, elementToNative);
                    }
                    return;
                }

                foreach (T item in value)
                {
                    helper.AddElement(item, elementToNative);
                }
            }
        }
Beispiel #11
0
 public TMapCopyMarshaler(int length, UFieldAddress mapProperty,
                          MarshalingDelegates <TKey> .FromNative keyFromNative, MarshalingDelegates <TKey> .ToNative keyToNative,
                          MarshalingDelegates <TValue> .FromNative valueFromNative, MarshalingDelegates <TValue> .ToNative valueToNative)
 {
     property             = mapProperty;
     helper               = new FScriptMapHelper(property.Address);
     this.keyFromNative   = keyFromNative;
     this.keyToNative     = keyToNative;
     this.valueFromNative = valueFromNative;
     this.valueToNative   = valueToNative;
 }
Beispiel #12
0
        public TArrayBase(UObject owner, UFieldAddress arrayProperty, IntPtr address,
                          MarshalingDelegates <T> .FromNative fromNative, MarshalingDelegates <T> .ToNative toNative)
        {
            property = arrayProperty;
            array    = (FScriptArray *)address;

            ArrayHelper = new FScriptArrayHelper(property.Address, address);

            Owner      = owner;
            FromNative = fromNative;
            ToNative   = toNative;
        }
Beispiel #13
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;
            }
        }
Beispiel #14
0
        public TSetBase(UObject owner, UFieldAddress setProperty, IntPtr address,
                        MarshalingDelegates <T> .FromNative fromNative, MarshalingDelegates <T> .ToNative toNative)
        {
            property = setProperty;
            set      = (FScriptSet *)address;

            SetHelper = new FScriptSetHelper(property.Address, address);

            Owner      = owner;
            FromNative = fromNative;
            ToNative   = toNative;

            ContainerHashValidator.Validate(Native_USetProperty.Get_ElementProp(setProperty.Address));
        }
        public void AddElement <T>(T item, MarshalingDelegates <T> .ToNative toNative)
        {
            unsafe
            {
                byte * temp    = stackalloc byte[elementSize * elementArrayDim];
                IntPtr tempPtr = (IntPtr)temp;
                Native_UProperty.InitializeValue(elementProp, tempPtr);
                toNative(tempPtr, 0, elementProp, item);

                AddElement(tempPtr);

                Native_UProperty.DestroyValue(elementProp, tempPtr);
            }
        }
        public int IndexOf <T>(T item, MarshalingDelegates <T> .ToNative toNative, UObject owner)
        {
            unsafe
            {
                byte * temp    = stackalloc byte[elementSize * elementArrayDim];
                IntPtr tempPtr = (IntPtr)temp;
                Native_UProperty.InitializeValue(elementProp, tempPtr);
                toNative(tempPtr, 0, elementProp, item);

                int index = FindElementIndexFromHash(tempPtr);

                Native_UProperty.DestroyValue(elementProp, tempPtr);

                return(index);
            }
        }
Beispiel #17
0
        public int FindPairIndex <TKey>(TKey key, MarshalingDelegates <TKey> .ToNative keyToNative, UObject owner)
        {
            unsafe
            {
                byte * tempKey    = stackalloc byte[keySize * keyArrayDim];
                IntPtr tempKeyPtr = (IntPtr)tempKey;
                Native_UProperty.InitializeValue(keyProp, tempKeyPtr);
                keyToNative(tempKeyPtr, 0, keyProp, key);

                int index = FindPairIndexFromHash(tempKeyPtr);

                Native_UProperty.DestroyValue(keyProp, tempKeyPtr);

                return(index);
            }
        }
Beispiel #18
0
        public TMapBase(UObject owner, UFieldAddress mapProperty, IntPtr address,
                        MarshalingDelegates <TKey> .FromNative keyFromNative, MarshalingDelegates <TKey> .ToNative keyToNative,
                        MarshalingDelegates <TValue> .FromNative valueFromNative, MarshalingDelegates <TValue> .ToNative valueToNative)
        {
            property = mapProperty;
            map      = (FScriptMap *)address;

            MapHelper = new FScriptMapHelper(property.Address, address);

            Owner           = owner;
            KeyFromNative   = keyFromNative;
            KeyToNative     = keyToNative;
            ValueFromNative = valueFromNative;
            ValueToNative   = valueToNative;

            ContainerHashValidator.Validate(Native_UMapProperty.Get_KeyProp(property.Address));
        }
Beispiel #19
0
        internal static void ToNativeInternal(IntPtr nativeBuffer, int arrayIndex, IDictionary <TKey, TValue> value,
                                              ref FScriptMapHelper helper, MarshalingDelegates <TKey> .ToNative keyToNative, MarshalingDelegates <TValue> .ToNative valueToNative)
        {
            IntPtr scriptMapAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptMap)));

            helper.Map = scriptMapAddress;

            // Make sure any existing elements are properly destroyed
            helper.EmptyValues();

            if (value == null)
            {
                return;
            }

            unsafe
            {
                FScriptMap *map = (FScriptMap *)scriptMapAddress;

                Dictionary <TKey, TValue> dictionary = value as Dictionary <TKey, TValue>;
                if (dictionary != null)
                {
                    foreach (KeyValuePair <TKey, TValue> pair in dictionary)
                    {
                        helper.AddPair(pair.Key, pair.Value, keyToNative, valueToNative);
                    }
                    return;
                }

                TMapBase <TKey, TValue> mapBase = value as TMapBase <TKey, TValue>;
                if (mapBase != null)
                {
                    foreach (KeyValuePair <TKey, TValue> pair in mapBase)
                    {
                        helper.AddPair(pair.Key, pair.Value, keyToNative, valueToNative);
                    }
                    return;
                }

                foreach (KeyValuePair <TKey, TValue> pair in value)
                {
                    helper.AddPair(pair.Key, pair.Value, keyToNative, valueToNative);
                }
            }
        }
Beispiel #20
0
        public void AddPair <TKey, TValue>(TKey key, TValue value, MarshalingDelegates <TKey> .ToNative keyToNative,
                                           MarshalingDelegates <TValue> .ToNative valueToNative)
        {
            unsafe
            {
                byte * tempKey    = stackalloc byte[keySize * keyArrayDim];
                IntPtr tempKeyPtr = (IntPtr)tempKey;
                Native_UProperty.InitializeValue(keyProp, tempKeyPtr);
                keyToNative(tempKeyPtr, 0, keyProp, key);

                byte * tempValue    = stackalloc byte[valueSize * valueArrayDim];
                IntPtr tempValuePtr = (IntPtr)tempValue;
                Native_UProperty.InitializeValue(valueProp, tempValuePtr);
                valueToNative(tempValuePtr, 0, valueProp, value);

                AddPair(tempKeyPtr, tempValuePtr);

                Native_UProperty.DestroyValue(keyProp, tempKeyPtr);
                Native_UProperty.DestroyValue(valueProp, tempValuePtr);
            }
        }
Beispiel #21
0
        internal static void ToNativeInternal(IntPtr nativeBuffer, int arrayIndex, IList <T> value,
                                              ref FScriptArrayHelper helper, MarshalingDelegates <T> .ToNative innerToNative)
        {
            IntPtr scriptArrayAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptArray)));

            helper.Array = scriptArrayAddress;

            // Make sure any existing elements are properly destroyed
            helper.EmptyAndAddZeroedValues(value == null ? 0 : value.Count);

            if (value == null)
            {
                return;
            }

            unsafe
            {
                FScriptArray *array = (FScriptArray *)scriptArrayAddress;
                for (int i = 0; i < value.Count; ++i)
                {
                    innerToNative(array->Data, i, helper.InnerPropertyAddress, value[i]);
                }
            }
        }
Beispiel #22
0
 public TArrayReadWrite(UObject owner, UFieldAddress arrayProperty, IntPtr address,
                        MarshalingDelegates <T> .FromNative fromNative, MarshalingDelegates <T> .ToNative toNative)
     : base(owner, arrayProperty, address, fromNative, toNative)
 {
 }
Beispiel #23
0
 public TArrayReadOnly(UObject owner, UFieldAddress arrayProperty, IntPtr address, MarshalingDelegates <T> .FromNative fromNative)
     : base(owner, arrayProperty, address, fromNative, null)
 {
 }
Beispiel #24
0
 public FixedSizeArray(UnrealObject owner, int propertyOffset, int length, MarshalingDelegates <T> .FromNative fromNative)
     : base(owner.NativeObject + propertyOffset, length, owner)
 {
     FromNative = fromNative;
 }
Beispiel #25
0
 public FixedSizeArrayReadOnly(UnrealObject owner, int propertyOffset, int length, MarshalingDelegates <T> .ToNative toNative, MarshalingDelegates <T> .FromNative fromNative)
     : base(owner, propertyOffset, length, fromNative)
 {
 }
Beispiel #26
0
 public FixedSizeArrayReadOnly(IntPtr nativeBuffer, int length, MarshalingDelegates <T> .ToNative toNative, MarshalingDelegates <T> .FromNative fromNative)
     : base(nativeBuffer, length, fromNative)
 {
 }
Beispiel #27
0
 public UnrealArrayReadWrite(UnrealObject baseObject, IntPtr nativeUnrealProperty, IntPtr nativeBuffer, MarshalingDelegates <T> .ToNative toNative, MarshalingDelegates <T> .FromNative fromNative)
     : base(baseObject, nativeUnrealProperty, nativeBuffer, toNative, fromNative)
 {
 }
Beispiel #28
0
 public UnrealArrayCopyMarshaler(int length, MarshalingDelegates <T> .ToNative toNative, MarshalingDelegates <T> .FromNative fromNative, int elementSize)
 {
     ElementSize         = elementSize;
     InnerTypeFromNative = fromNative;
     InnerTypeToNative   = toNative;
 }
Beispiel #29
0
 public TMapReadWrite(UObject owner, UFieldAddress mapProperty, IntPtr address,
                      MarshalingDelegates <TKey> .FromNative keyFromNative, MarshalingDelegates <TKey> .ToNative keyToNative,
                      MarshalingDelegates <TValue> .FromNative valueFromNative, MarshalingDelegates <TValue> .ToNative valueToNative)
     : base(owner, mapProperty, address, keyFromNative, keyToNative, valueFromNative, valueToNative)
 {
 }
Beispiel #30
0
 public FixedSizeArray(IntPtr nativeBuffer, int length, MarshalingDelegates <T> .FromNative fromNative)
     : base(nativeBuffer, length, null)
 {
     FromNative = fromNative;
 }