コード例 #1
0
        public unsafe void Apply()
        {
            IntPtr returnedException = default;

            UnityInternals.runtime_invoke(m_Apply, UnityInternals.ObjectBaseToPtrNotNull(this), (void **)0, ref returnedException);
            Il2CppException.RaiseExceptionIfNecessary(returnedException);
        }
コード例 #2
0
ファイル: Mesh.cs プロジェクト: studentutu/MelonLoader
        public unsafe Mesh() : base(UnityInternals.object_new(InternalClassPointerStore <Mesh> .NativeClassPtr))
        {
            IntPtr returnedException = default;

            UnityInternals.runtime_invoke(m_ctor, UnityInternals.ObjectBaseToPtrNotNull(this), (void **)0, ref returnedException);
            Il2CppException.RaiseExceptionIfNecessary(returnedException);
        }
コード例 #3
0
ファイル: Mesh.cs プロジェクト: studentutu/MelonLoader
        public unsafe void RecalculateBounds()
        {
            UnityInternals.ObjectBaseToPtrNotNull(this);
            IntPtr returnedException = default;

            UnityInternals.runtime_invoke(m_RecalculateBounds, UnityInternals.ObjectBaseToPtrNotNull(this), (void **)0, ref returnedException);
            Il2CppException.RaiseExceptionIfNecessary(returnedException);
        }
コード例 #4
0
        private unsafe static bool SafeInvokeMoveNext(IntPtr methodPtr, IntPtr thisPtr)
        {
            var exc = IntPtr.Zero;

            ((Il2CppMethodInfo *)ourInvokeMethodInfo)->methodPointer = methodPtr;
            var result = IL2CPP.il2cpp_runtime_invoke(ourInvokeMethodInfo, thisPtr, (void **)IntPtr.Zero, ref exc);

            Il2CppException.RaiseExceptionIfNecessary(exc);
            return(*(bool *)IL2CPP.il2cpp_object_unbox(result));
        }
コード例 #5
0
        public unsafe Texture2D(int width, int height) : base(UnityInternals.object_new(InternalClassPointerStore <Texture2D> .NativeClassPtr))
        {
            void **args = stackalloc void *[2];

            args[0] = &width;
            args[1] = &height;
            IntPtr returnedException = default;

            UnityInternals.runtime_invoke(m_ctor, UnityInternals.ObjectBaseToPtrNotNull(this), args, ref returnedException);
            Il2CppException.RaiseExceptionIfNecessary(returnedException);
        }
コード例 #6
0
        public unsafe static Type internal_from_handle(IntPtr handle)
        {
            void **args = stackalloc void *[1];

            args[0] = &handle;
            IntPtr returnedException = default;
            IntPtr intPtr            = UnityInternals.runtime_invoke(Type.m_internal_from_handle, IntPtr.Zero, (void **)args, ref returnedException);

            Il2CppException.RaiseExceptionIfNecessary(returnedException);
            return((intPtr != IntPtr.Zero) ? new Type(intPtr) : null);
        }
コード例 #7
0
ファイル: TextGenerator.cs プロジェクト: yowchap/MelonLoader
        public unsafe bool Populate(string str, TextGenerationSettings settings)
        {
            void **args = stackalloc void *[2];

            args[0] = (void *)UnityInternals.ManagedStringToInternal(str);
            args[1] = (void *)UnityInternals.object_unbox(UnityInternals.ObjectBaseToPtrNotNull(settings));
            IntPtr returnedException = default;
            IntPtr obj = UnityInternals.runtime_invoke(m_Populate, UnityInternals.ObjectBaseToPtrNotNull(this), args, ref returnedException);

            Il2CppException.RaiseExceptionIfNecessary(returnedException);
            return(*(bool *)UnityInternals.object_unbox(obj));
        }
コード例 #8
0
        public unsafe static IntPtr GetUnityTlsInterface()
        {
            if (m_GetUnityTlsInterface == null)
            {
                return(IntPtr.Zero);
            }

            IntPtr *param             = null;
            IntPtr  returnedException = IntPtr.Zero;
            IntPtr  intPtr            = UnityInternals.il2cpp_runtime_invoke(m_GetUnityTlsInterface, IntPtr.Zero, (void **)param, ref returnedException);

            Il2CppException.RaiseExceptionIfNecessary(returnedException);
            return(*(IntPtr *)UnityInternals.il2cpp_object_unbox(intPtr));
        }
コード例 #9
0
        public unsafe static IntPtr GetBuiltinResource(Il2CppSystem.Type type, string path)
        {
            void **ptr = stackalloc void *[2];

            ptr[0] = (void *)UnityInternals.ObjectBaseToPtr(type);
            ptr[1] = (void *)UnityInternals.ManagedStringToInternal(path);
            IntPtr returnedException = default;

            MelonDebug.Msg("Calling runtime_invoke for GetBuiltinResource");
            IntPtr objectPointer = UnityInternals.runtime_invoke(m_GetBuiltinResource, IntPtr.Zero, ptr, ref returnedException);

            MelonDebug.Msg("returnedException: " + returnedException + ", objectPointer: " + objectPointer);
            Il2CppException.RaiseExceptionIfNecessary(returnedException);
            return(objectPointer);
        }
コード例 #10
0
        unsafe public void DontDestroyOnLoad()
        {
            if (Pointer == IntPtr.Zero)
            {
                return;
            }

            void **args = stackalloc void *[1];

            args[0] = Pointer.ToPointer();

            IntPtr returnedException = IntPtr.Zero;

            UnityInternals.runtime_invoke(m_DontDestroyOnLoad, IntPtr.Zero, args, ref returnedException);
            Il2CppException.RaiseExceptionIfNecessary(returnedException);
        }
コード例 #11
0
 public unsafe static Il2CppSystem.Type GetIl2CppTypeSafe(this object that)
 {
     if (that is Il2CppObjectBase obj)
     {
         UnhollowerBaseLib.IL2CPP.Il2CppObjectBaseToPtrNotNull(obj);
         System.IntPtr *param  = null;
         System.IntPtr  exc    = IntPtr.Zero;
         System.IntPtr  intPtr = UnhollowerBaseLib.IL2CPP.il2cpp_runtime_invoke(
             GetIl2CppType,
             UnhollowerBaseLib.IL2CPP.Il2CppObjectBaseToPtrNotNull(obj),
             (void **)param,
             ref exc);
         Il2CppException.RaiseExceptionIfNecessary(exc);
         return(intPtr != IntPtr.Zero ? new Il2CppSystem.Type(intPtr) : null);
     }
     return(null);
 }
コード例 #12
0
ファイル: Item.cs プロジェクト: hnllc1/ModBahuang
        public ConfBaseItem Construct()
        {
            var o   = IL2CPP.il2cpp_object_new(record.NativeItemClassPtr);
            var obj = (ConfBaseItem)record.ItemType
                      .GetConstructor(new[] { typeof(IntPtr) })?
                      .Invoke(new object[] { o });

            var paramLen = values.Length + 1;

            unsafe
            {
                var args = stackalloc IntPtr[paramLen];

                var id = Id;
                args[0] = (IntPtr)(&id);

                fixed(Value *arr = values)
                {
                    for (var i = 1; i < paramLen; i++)
                    {
                        var j = i - 1;
                        var v = &arr[j];

                        if (v->IsNone)
                        {
                            Logger.Warn($"Required field({record.FieldsInfo[j].Item1}) does not exsit in item(id: {Id}, @ {Source}), set to default.");
                        }

                        // FIXME: Is it REALLY safe?
                        args[i] = v->Ptr();
                    }
                    var exc = IntPtr.Zero;

                    IL2CPP.il2cpp_runtime_invoke(record.ItemCtor.Item2, IL2CPP.Il2CppObjectBaseToPtrNotNull(obj), (void **)args, ref exc);
                    Il2CppException.RaiseExceptionIfNecessary(exc);
                }
            }

            return(obj);
        }
コード例 #13
0
        unsafe public static IntPtr InvokeMethod(IntPtr method, IntPtr obj, params IntPtr[] paramtbl)
        {
            if (method == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }



            if (paramtbl == null || paramtbl.Length == 0)
            {
                IntPtr *parameters = null;
                IntPtr  exp        = IntPtr.Zero;
                var     returnval  = IL2CPP.il2cpp_runtime_invoke(method, obj, (void **)parameters, ref exp);
                Il2CppException.RaiseExceptionIfNecessary(exp);
                return(returnval);
            }
            else
            {
                fixed(IntPtr *ptr = &paramtbl[0])
                {
                    IntPtr exp       = IntPtr.Zero;
                    var    returnval = IL2CPP.il2cpp_runtime_invoke(method, obj, (void **)ptr, ref exp);

                    Il2CppException.RaiseExceptionIfNecessary(exp);
                    return(returnval);
                }
            }



            //var cnt = paramtbl?.Length ?? 0;
            //var parameters = stackalloc IntPtr[ cnt ];
            //for( int i = 0; i < cnt; i++ )
            //{
            //   parameters[ i ] = paramtbl[ i ];
            //}

            //IntPtr exp = IntPtr.Zero;
            //var returnval = UnhollowerBaseLib.IL2CPP.il2cpp_runtime_invoke( method, obj, (void**)parameters, ref exp );
            //Il2CppException.RaiseExceptionIfNecessary( exp );
            //return returnval;



            //IntPtr[] intPtrArray;
            //IntPtr returnval = IntPtr.Zero;
            //intPtrArray = ( ( paramtbl != null ) ? paramtbl : new IntPtr[ 0 ] );
            //IntPtr intPtr = Marshal.AllocHGlobal( intPtrArray.Length * sizeof( void* ) );
            //try
            //{
            //   void** pointerArray = (void**)intPtr.ToPointer();
            //   for( int i = 0; i < intPtrArray.Length; i++ )
            //      pointerArray[ i ] = intPtrArray[ i ].ToPointer();
            //   IntPtr exp = IntPtr.Zero;
            //   returnval = UnhollowerBaseLib.IL2CPP.il2cpp_runtime_invoke( method, obj, pointerArray, ref exp );
            //   Il2CppException.RaiseExceptionIfNecessary( exp );
            //}
            //finally
            //{
            //   Marshal.FreeHGlobal( intPtr );
            //}
            //return returnval;
        }