public FScriptArrayHelper(IntPtr arrayProperty, IntPtr array) { innerProperty = Native_UArrayProperty.Get_Inner(arrayProperty); this.arrayProperty = arrayProperty; this.array = (FScriptArray *)array; elementSize = Native_UProperty.Get_ElementSize(innerProperty); }
public unsafe T GetInterface <T>() where T : class, IInterface { T result = this as T; if (result != null) { return(result); } if (injectedInterfaces == null) { // If the injected interfaces haven't been set up set them up now if (objRef == null) { return(null); } UClass unrealClass = GetClass(); if (unrealClass as USharpClass != null) { // This is a C# defined type. We know if it implements the target interface or not due to the // above "this as T". There isn't any need to inject interfaces into the UObject. return(null); } FScriptArray *interfacesPtr = (FScriptArray *)Native_UClass.Get_InterfacesRef(unrealClass.Address); if (interfacesPtr->ArrayNum != 0) { injectedInterfaces = new Dictionary <Type, IInterface>(); foreach (FImplementedInterface implementedInterface in unrealClass.Interfaces) { if (implementedInterface.InterfaceClassAddress != IntPtr.Zero) { Type type = UClass.GetTypeFromClassAddress(implementedInterface.InterfaceClassAddress); if (type != null) { IInterface instance = UnrealInterfacePool.New(type, objRef); if (instance != null) { injectedInterfaces[type] = instance; if (type == typeof(T)) { result = instance as T; } } } } } } } else { // Try and get the interface from the injected interfaces. IInterface instance; injectedInterfaces.TryGetValue(typeof(T), out instance); result = instance as T; } return(result); }
public TArrayUnsafe() { address = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FScriptArray))); nativeArray = (FScriptArray *)address; nativeArray->Data = IntPtr.Zero; nativeArray->ArrayNum = 0; nativeArray->ArrayMax = 0; ValidateType(); }
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; }
public static IList <T> FromNative(IntPtr nativeBuffer, int arrayIndex, IntPtr prop) { IntPtr scriptArrayAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptArray))); FScriptArrayHelper helper = new FScriptArrayHelper(prop, scriptArrayAddress); unsafe { FScriptArray *array = (FScriptArray *)scriptArrayAddress; List <T> result = new List <T>(array->ArrayNum); for (int i = 0; i < array->ArrayNum; ++i) { result.Add(innerFromNative(array->Data, i, helper.InnerPropertyAddress)); } return(result); } }
public void Dispose() { if (isRef) { return; } if (nativeArray != null) { Clear(); nativeArray->Destroy(); nativeArray = null; } if (address != IntPtr.Zero) { Marshal.FreeHGlobal(address); address = IntPtr.Zero; } }
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]); } } }
public TArrayUnsafe(IntPtr native) { nativeArray = (FScriptArray *)native; ValidateType(); }
public T this[int index] { get { if (!nativeArray->IsValidIndex(index)) { throw new IndexOutOfRangeException(); } IntPtr address = IntPtr.Add(nativeArray->Data, numBytesPerElement * index); if (isUObject) { return((T)(object)GCHelper.Find(Marshal.ReadIntPtr(address))); } else if (isString) { return((T)(object)FStringMarshaler.FromPtr(address)); } else { return((T)Marshal.PtrToStructure(address, typeof(T))); } } set { if (!nativeArray->IsValidIndex(index)) { throw new IndexOutOfRangeException(); } IntPtr address = IntPtr.Add(nativeArray->Data, numBytesPerElement * index); if (isUObject) { if (value == null) { Marshal.WriteIntPtr(address, IntPtr.Zero); } else { UObject obj = (UObject)(object)value; Marshal.WriteIntPtr(address, obj.Address); } } else if (isString) { unsafe { // Get the current value, clear the current value and write the new value FScriptArray *current = (FScriptArray *)address; current->Destroy(); string valueStr = value == null ? null : (string)(object)value; if (!string.IsNullOrEmpty(valueStr)) { FStringMarshaler.ToArray(address, valueStr); } } } else { Marshal.StructureToPtr(value, address, false); } } }