Пример #1
0
        public static bool Method(string name, IL2Type il2type, ref IL2Method il2method)
        {
            if (il2method == null)
            {
                il2method = il2type.GetMethod(name);
            }

            return(il2method != null);
        }
Пример #2
0
        public unsafe static IntPtr CreateDelegate <T>(Delegate function, T instance, IL2Type klass = null)
        {
            if (klass == null)
            {
                klass = Instance_Class;
            }

            var obj = IL2Import.il2cpp_object_new(klass.ptr);

            if (instance == null || (typeof(T) == typeof(IntPtr) && (IntPtr)(object)instance == IntPtr.Zero))
            {
                var runtimeStaticMethod = Marshal.AllocHGlobal(8);
                *(IntPtr *)runtimeStaticMethod = function.Method.MethodHandle.GetFunctionPointer();
                *((IntPtr *)obj + 2)           = function.Method.MethodHandle.GetFunctionPointer();
                *((IntPtr *)obj + 4)           = IntPtr.Zero;
                *((IntPtr *)obj + 5)           = runtimeStaticMethod;
                return(obj);
            }

            IL2Method ctor          = klass.GetMethod(".ctor");
            GCHandle  handle1       = GCHandle.Alloc(instance);
            var       runtimeMethod = Marshal.AllocHGlobal(80);

            //methodPtr
            *((IntPtr *)runtimeMethod) = function.Method.MethodHandle.GetFunctionPointer();
            byte paramCount = (byte)(function.Method.GetParameters()?.Length ?? 0);

            //Parameter count
            *((byte *)runtimeMethod + 75) = 0; // 0 parameter_count

            //Slot (65535)
            *((byte *)runtimeMethod + 74) = 0xFF;
            *((byte *)runtimeMethod + 73) = 0xFF;

            *((IntPtr *)obj + 2) = function.Method.MethodHandle.GetFunctionPointer();
            *((IntPtr *)obj + 4) = obj;
            *((IntPtr *)obj + 5) = runtimeMethod;
            *((IntPtr *)obj + 7) = GCHandle.ToIntPtr(handle1);

            return(obj);
        }