Beispiel #1
0
        private static unsafe IntPtr OnAdd(IntPtr native)
        {
            UObjectRef objRef = null;
            int        objectInternalIndex = *(int *)(native + objectInternalIndexOffset);

#if ARRAY_GC
            while (References.Count <= objectInternalIndex)
            {
                References.Add(null);
            }
            if (References[objectInternalIndex] == null)
#else
            if (!References.TryGetValue(native, out objRef))
#endif
            {
                bool isKnownType;
                Type type = UClass.GetFirstKnownType(native, out isKnownType, false);
                if (type == null)
                {
                    // This probably means the given address is not valid (check IsValid/IsValidLowLevel/IsValidLowLevelFast ?)
                    string className = string.Empty;
                    string fullName  = string.Empty;
                    try
                    {
                        using (FStringUnsafe classNameUnsafe = new FStringUnsafe())
                        {
                            Native_UObjectBaseUtility.GetName(Native_UObjectBase.GetClass(native), ref classNameUnsafe.Array);
                            className = classNameUnsafe.Value;
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        using (FStringUnsafe fullNameUnsafe = new FStringUnsafe())
                        {
                            Native_UObjectBaseUtility.GetFullName(native, IntPtr.Zero, ref fullNameUnsafe.Array);
                            fullName = fullNameUnsafe.Value;
                        }
                    }
                    catch
                    {
                    }
                    // Get a smaller stack snippet
                    StackTrace stack = null;
                    try
                    {
                        stack = new StackTrace(4);
                    }
                    catch
                    {
                    }
                    string error = string.Format("[GCHelper-Error] Couldn't find type for requested UObject. Address: {0} (0x{1}) Name: \"{2}\" FullName: \"{3}\" Stack:\r\n{4}",
                                                 native.ToInt32(), native.ToInt32().ToString("X8"), className, fullName, stack);
                    FMessage.Log(ELogVerbosity.Error, error);
                    Debug.Assert(false, error);
                    return(IntPtr.Zero);
                }
                if (type.IsInterface)
                {
                    // Validate that we are getting a UInterface and we aren't doing something very wrong.
                    Debug.Assert(Native_UObjectBaseUtility.IsA(native, UClass.GetClassAddress(type)));

                    // This should be a UInterface instance. We might want to do something more complex here
                    // where interfaces inherit from other interfaces.
                    type = typeof(UInterface);
                }
                objRef = objRefPool.New(native, type, isKnownType, objectInternalIndex);
#if ARRAY_GC
                References[objectInternalIndex] = objRef;
#else
                References.Add(native, objRef);
#endif
                return(GCHandle.ToIntPtr(objRef.ManagedHandle));
            }
            return(GCHandle.ToIntPtr(objRef.ManagedHandle));
        }