Exemple #1
0
 public void DeltaAddEncoder(string name, ConditionalencodeDelegateManaged conditionalencode)
 {
     ef.DeltaAddEncoder(name, Marshal.GetFunctionPointerForDelegate(conditionalencode));
 }
                    /// <summary>Gets the list of Eo operations to override.</summary>
                    /// <returns>The list of Eo operations to be overload.</returns>
                    public override System.Collections.Generic.List <Efl_Op_Description> GetEoOps(System.Type type)
                    {
                        var descs   = new System.Collections.Generic.List <Efl_Op_Description>();
                        var methods = Efl.Eo.Globals.GetUserMethods(type);

                        if (efl_ui_focus_manager_root_focus_canvas_object_get_static_delegate == null)
                        {
                            efl_ui_focus_manager_root_focus_canvas_object_get_static_delegate = new efl_ui_focus_manager_root_focus_canvas_object_get_delegate(canvas_object_get);
                        }

                        if (methods.FirstOrDefault(m => m.Name == "GetCanvasObject") != null)
                        {
                            descs.Add(new Efl_Op_Description()
                            {
                                api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_focus_manager_root_focus_canvas_object_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_focus_manager_root_focus_canvas_object_get_static_delegate)
                            });
                        }

                        if (efl_ui_focus_manager_root_focus_canvas_object_set_static_delegate == null)
                        {
                            efl_ui_focus_manager_root_focus_canvas_object_set_static_delegate = new efl_ui_focus_manager_root_focus_canvas_object_set_delegate(canvas_object_set);
                        }

                        if (methods.FirstOrDefault(m => m.Name == "SetCanvasObject") != null)
                        {
                            descs.Add(new Efl_Op_Description()
                            {
                                api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_focus_manager_root_focus_canvas_object_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_focus_manager_root_focus_canvas_object_set_static_delegate)
                            });
                        }

                        descs.AddRange(base.GetEoOps(type));
                        return(descs);
                    }
Exemple #3
0
        public void SetInterceptCallback(InterceptCallback callback)
        {
            ThrowIfNotCreated();

            Native.enet_host_set_intercept_callback(nativeHost, Marshal.GetFunctionPointerForDelegate(callback));
        }
Exemple #4
0
                /// <summary>Gets the list of Eo operations to override.</summary>
                /// <returns>The list of Eo operations to be overload.</returns>
                public override System.Collections.Generic.List <Efl_Op_Description> GetEoOps(System.Type type)
                {
                    var descs   = new System.Collections.Generic.List <Efl_Op_Description>();
                    var methods = Efl.Eo.Globals.GetUserMethods(type);

                    if (efl_access_selection_selected_children_count_get_static_delegate == null)
                    {
                        efl_access_selection_selected_children_count_get_static_delegate = new efl_access_selection_selected_children_count_get_delegate(selected_children_count_get);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "GetSelectedChildrenCount") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_access_selection_selected_children_count_get"), func = Marshal.GetFunctionPointerForDelegate(efl_access_selection_selected_children_count_get_static_delegate)
                        });
                    }

                    if (efl_access_selection_selected_child_get_static_delegate == null)
                    {
                        efl_access_selection_selected_child_get_static_delegate = new efl_access_selection_selected_child_get_delegate(selected_child_get);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "GetSelectedChild") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_access_selection_selected_child_get"), func = Marshal.GetFunctionPointerForDelegate(efl_access_selection_selected_child_get_static_delegate)
                        });
                    }

                    if (efl_access_selection_child_select_static_delegate == null)
                    {
                        efl_access_selection_child_select_static_delegate = new efl_access_selection_child_select_delegate(child_select);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "ChildSelect") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_access_selection_child_select"), func = Marshal.GetFunctionPointerForDelegate(efl_access_selection_child_select_static_delegate)
                        });
                    }

                    if (efl_access_selection_selected_child_deselect_static_delegate == null)
                    {
                        efl_access_selection_selected_child_deselect_static_delegate = new efl_access_selection_selected_child_deselect_delegate(selected_child_deselect);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "SelectedChildDeselect") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_access_selection_selected_child_deselect"), func = Marshal.GetFunctionPointerForDelegate(efl_access_selection_selected_child_deselect_static_delegate)
                        });
                    }

                    if (efl_access_selection_is_child_selected_static_delegate == null)
                    {
                        efl_access_selection_is_child_selected_static_delegate = new efl_access_selection_is_child_selected_delegate(is_child_selected);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "IsChildSelected") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_access_selection_is_child_selected"), func = Marshal.GetFunctionPointerForDelegate(efl_access_selection_is_child_selected_static_delegate)
                        });
                    }

                    if (efl_access_selection_all_children_select_static_delegate == null)
                    {
                        efl_access_selection_all_children_select_static_delegate = new efl_access_selection_all_children_select_delegate(all_children_select);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "AllChildrenSelect") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_access_selection_all_children_select"), func = Marshal.GetFunctionPointerForDelegate(efl_access_selection_all_children_select_static_delegate)
                        });
                    }

                    if (efl_access_selection_clear_static_delegate == null)
                    {
                        efl_access_selection_clear_static_delegate = new efl_access_selection_clear_delegate(access_selection_clear);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "ClearAccessSelection") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_access_selection_clear"), func = Marshal.GetFunctionPointerForDelegate(efl_access_selection_clear_static_delegate)
                        });
                    }

                    if (efl_access_selection_child_deselect_static_delegate == null)
                    {
                        efl_access_selection_child_deselect_static_delegate = new efl_access_selection_child_deselect_delegate(child_deselect);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "ChildDeselect") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_access_selection_child_deselect"), func = Marshal.GetFunctionPointerForDelegate(efl_access_selection_child_deselect_static_delegate)
                        });
                    }

                    return(descs);
                }
Exemple #5
0
 protected BroadphaseRayCallback()
     : base(IntPtr.Zero)
 {
     _native = btBroadphaseRayCallbackWrapper_new(
         Marshal.GetFunctionPointerForDelegate(_process));
 }
Exemple #6
0
        public override System.Collections.Generic.List <Efl_Op_Description> GetEoOps(System.Type type)
        {
            var descs = new System.Collections.Generic.List <Efl_Op_Description>();

            if (efl_ui_item_index_get_static_delegate == null)
            {
                efl_ui_item_index_get_static_delegate = new efl_ui_item_index_get_delegate(index_get);
            }
            descs.Add(new Efl_Op_Description()
                {
                    api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_item_index_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_item_index_get_static_delegate)
                });
            if (efl_ui_item_selected_get_static_delegate == null)
            {
                efl_ui_item_selected_get_static_delegate = new efl_ui_item_selected_get_delegate(selected_get);
            }
            descs.Add(new Efl_Op_Description()
                {
                    api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_item_selected_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_item_selected_get_static_delegate)
                });
            if (efl_ui_item_selected_set_static_delegate == null)
            {
                efl_ui_item_selected_set_static_delegate = new efl_ui_item_selected_set_delegate(selected_set);
            }
            descs.Add(new Efl_Op_Description()
                {
                    api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_item_selected_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_item_selected_set_static_delegate)
                });
            descs.AddRange(base.GetEoOps(type));
            return(descs);
        }
Exemple #7
0
        /*
         *  signup or signin with nonce.
         *  nonce is the parameter which help more accurate validation of idToken on your application server.
         *
         *  recommended way of the SIWA authentication with nonce is below.
         *  1. client gets the nonce from your application server. server should record generated nonce.
         *  2. client should use the nonce to execute SignupOrSignin(nonce, (isSignup, SIWA userInfo) => {do sending idToken and other data to your server}) method.
         *  3. application server receives the idToken included the nonce. do delete record of the nonce and validate idToken with nonce. this way gives you to accurate JWT verification and avoid replay attack.
         */
        public static void SignupOrSignin(string nonce, AuthorizationScope authorizationScope, Action <bool, UserInfo> onSucceeded, Action <int, string> onFailed)
        {
            switch (state)
            {
            case State.None:
                break;

            default:
                onFailed(-1, "another process running. waiting for end of:" + state);
                return;
            }

            state = State.SignUpProcessing;

            signupCompletedCallback = args =>
            {
                state = State.None;


                var userInfo = args.userInfo;

                // success
                if (userInfo.errorCode == 0)
                {
                    /*
                     *  success
                     *  {
                     *      "userId": "000692.40362e95611641bbb392d7dddc6b25ca.1447",
                     *      "email": "[email protected]",
                     *      "displayName": "xxxxx",
                     *      "authorizationCode": "c4902247f521c4104ba925bbc17143b8c.0.nwzs.l8YIwin6RbYr9aYGlRMoQg",
                     *      "idToken": "eyJraWQiOiI4NkQ4OEtmIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLmtpYWFraS50ZXN0IiwiZXhwIjoxNTg0MDExMTk1LCJpYXQiOjE1ODQwMTA1OTUsInN1YiI6IjAwMDY5Mi40MDM2MmU5NTYxMTY0MWJiYjM5MmQ3ZGRkYzZiMjVjYS4xNDQ3IiwiY19oYXNoIjoiUms5RHk4aGhvSUhUR2NTWlVjbkFhdyIsImVtYWlsIjoiOHp0OGpteTVieEBwcml2YXRlcmVsYXkuYXBwbGVpZC5jb20iLCJlbWFpbF92ZXJpZmllZCI6InRydWUiLCJpc19wcml2YXRlX2VtYWlsIjoidHJ1ZSIsImF1dGhfdGltZSI6MTU4NDAxMDU5NSwibm9uY2Vfc3VwcG9ydGVkIjp0cnVlfQ.LWDdtt-AS42QbgfO6q2zfe2uJ7rvsQNgUz8phrOO4sltT4fNPMdJDAcdpHj7wuEYUhSoC4lKSTzEyVOSqXzxHNrWah6VEki49vWmNlHObTTdEHyfh6zhjj5Keve5WWO-1s7kmPu6eEFeyz3gAbvRPpck_tTWgx6N6-oijdccTy4jdstAt5mxUtzhT-oPw8LvEC0kLpRhZyOcjfiFsMZ2AFXzkQAbl6JaKdrvSZNcgM-VbzJrfg4b_bS14FAPqKN3ZJ_ksSvyaY3ugI0NBT_rUeINugOoABwk1h1bv7RW4R66Pmg5oAGDH_m3AwKkFkltIbZyAMXsmP3HU6iMr2iquA",
                     *      "error": "",
                     *      "userDetectionStatus": 1
                     *  }
                     */

                    // Debug.Log("data:" + JsonUtility.ToJson(userInfo));

                    var publicUserInfo = new UserInfo(
                        userInfo.authorizationCode,
                        userInfo.userId,
                        userInfo.email,
                        userInfo.displayName,
                        userInfo.idToken,
                        userInfo.userDetectionStatus
                        );

                    // check if requested authorizationScope data is contained or not.
                    // if requested but not contained, the request is not first one.
                    // determine the result as "signin".
                    var isSignin = false;
                    switch (authorizationScope)
                    {
                    case AuthorizationScope.Email:
                        isSignin = string.IsNullOrEmpty(publicUserInfo.email);
                        break;

                    case AuthorizationScope.FullName:
                        isSignin = string.IsNullOrEmpty(publicUserInfo.displayName);
                        break;

                    case AuthorizationScope.EmailAndFullName:
                        isSignin = string.IsNullOrEmpty(publicUserInfo.email) && string.IsNullOrEmpty(publicUserInfo.displayName);
                        break;
                    }

                    if (isSignin)
                    {
                        // signin.
                        onSucceeded(false, publicUserInfo);
                        return;
                    }

                    // signup.
                    onSucceeded(true, publicUserInfo);
                    return;
                }

                /*
                 *  {
                 *      "userInfo": {
                 *          "userId": "",
                 *          "email": "",
                 *          "displayName": "",
                 *          "authorizationCode": "",
                 *          "idToken": "",
                 *          "error": "",
                 *          "userDetectionStatus": 0
                 *      }
                 *      "error": "The operation couldn’t be completed. (com.apple.AuthenticationServices.AuthorizationError error 1001.)"
                 *  }
                 */
                // error
                onFailed(userInfo.errorCode, userInfo.reason);
            };

#if UNITY_EDITOR
            state = State.None;
            onSucceeded(
                true,
                new UserInfo(
                    "dummy authorizationCode",
                    "dummy userId",
                    "dummy email",
                    "dummy displayName",
                    "dummy idToken",
                    UserDetectionStatus.LikelyReal
                    )
                );
#elif UNITY_IOS
            IntPtr          cback = IntPtr.Zero;
            SignupCompleted d     = SignupCompletedCallback;
            cback = Marshal.GetFunctionPointerForDelegate(d);

            SignInWithApple_Signup(nonce, (int)authorizationScope, cback);
#endif
        }
Exemple #8
0
        public void LuaPushFunction(LuaCSFunction func)
        {
            IntPtr fn = Marshal.GetFunctionPointerForDelegate(func);

            LuaDLL.lua_pushcclosure(L, fn, 0);
        }
Exemple #9
0
        public void Start(bool useUsb, Action <string> consoleCallback)
        {
            string serial = "";             // Only when using USB do you need an actual 'serial' name.
            int    ret;

            if (useUsb || !string.IsNullOrEmpty(package))
            {
                Console.WriteLine("Waiting for Vita to connect...");
                ScePsmDevice?vita = null;
                for (; ;)
                {
                    ScePsmDevice[] deviceArray;
                    PSMFunctions.ListDevices(out deviceArray);
                    foreach (ScePsmDevice dev in deviceArray)
                    {
                        if (dev.online > 0)
                        {
                            vita = dev;
                            break;
                        }
                    }
                    if (vita != null)
                    {
                        break;
                    }
                }
                Guid devId = vita.Value.guid;
                serial = new string(vita.Value.deviceID, 0, 17);
                Console.WriteLine("Found Vita {0}, serial: {1}", devId, serial);
                if ((ret = PSMFunctions.Connect(devId)) < 0)
                {
                    Console.WriteLine("Error connecting to Vita: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }
                this.handle = devId;

                // request version or other calls will fail
#if USE_UNITY
                string devagentver      = null;
                string hosttransportver = null;
                if ((ret = PSMFunctions.GetAgentVersion(this.handle, ref devagentver, ref hosttransportver)) != 0)
                {
                    Console.WriteLine("Error getting version: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }
                Console.WriteLine("Connected agent version: {0}, transport version: {1}", devagentver, hosttransportver);
#else
                PSMFunctions.Version(this.handle);
#endif

#if USE_APP_KEY
                byte[] buffer = File.ReadAllBytes("kdev.p12");

                if ((ret = PSMFunctions.ExistAppExeKey(this.handle, DRMFunctions.ReadAccountIdFromKdevP12(buffer), "*", "np")) != 1)
                {
                    Console.WriteLine("Setting app key to: {0}", appkeypath);
                    if ((ret = PSMFunctions.SetAppExeKey(this.handle, appkeypath)) != 0)
                    {
                        Console.WriteLine("Error setting key: 0x{0:X}", ret);
                        throw new IOException("Cannot set app key.");
                    }
                }
#endif
            }

            if (!string.IsNullOrEmpty(package))
            {
                Console.WriteLine("Installing package {0} as {1}.", package, name);
                if ((ret = PSMFunctions.Install(this.handle, package, name)) != 0)
                {
                    Console.WriteLine("Error installing package: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }

                Console.WriteLine("Successfully installed package.");

                Thread.Sleep(500);

#if !USE_ANDROID
                if (Program.exitAfterInstall)
                {
                    Environment.Exit(0);
                }
#endif
            }

            if (useUsb)
            {
                callback = new PsmDeviceConsoleCallback(consoleCallback);
                Console.WriteLine("Setting console callback.");
                PSMFunctions.SetConsoleWrite(this.handle, Marshal.GetFunctionPointerForDelegate(callback));

                Console.WriteLine("Launching {0}.", name);
#if USE_UNITY
                if ((ret = PSMFunctions.LaunchUnity(this.handle, name, 0, new string[] { })) != 0)
                {
                    Console.WriteLine("Error running application: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }
#else
                if ((ret = PSMFunctions.Launch(this.handle, name, true, false, false, false, "")) != 0)
                {
                    Console.WriteLine("Error running application: 0x{0:X}", ret);
                    throw new IOException("Cannot connect to Vita.");
                }
#endif
            }

            Console.WriteLine("Connecting debugger.");
            conn = getconn(serial);
            conn.EventHandler  = new ConnEventHandler();
            conn.ErrorHandler += HandleConnErrorHandler;
            conn.Connect(out reciever);

            Console.WriteLine("Waiting for app to start up...");
#if !USE_UNITY
            conn.VM_Resume();
#endif
            Thread.Sleep(2000);
            Console.WriteLine("Getting variables.");
            rootdomain = conn.RootDomain;
            corlibid   = conn.Domain_GetCorlib(rootdomain);
            assid      = conn.Domain_GetEntryAssembly(rootdomain);
            foreach (long thread in conn.VM_GetThreads())
            {
                if (conn.Thread_GetName(thread) == "")
                {
                    threadid = thread;
                }
            }
            //Console.WriteLine ("Root Domain: {0}\nCorlib: {1}\nExeAssembly: {2}\nThread: {3}", rootdomain, corlibid, assid, threadid);
            Console.WriteLine("Ready for hacking.");
        }
Exemple #10
0
 public override System.Collections.Generic.List<Efl_Op_Description> GetEoOps(System.Type type)
 {
     var descs = new System.Collections.Generic.List<Efl_Op_Description>();
     var methods = Efl.Eo.Globals.GetUserMethods(type);
     if (efl_ui_stack_push_static_delegate == null)
         efl_ui_stack_push_static_delegate = new efl_ui_stack_push_delegate(push);
     if (methods.FirstOrDefault(m => m.Name == "Push") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_push"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_push_static_delegate)});
     if (efl_ui_stack_pop_static_delegate == null)
         efl_ui_stack_pop_static_delegate = new efl_ui_stack_pop_delegate(pop);
     if (methods.FirstOrDefault(m => m.Name == "Pop") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_pop"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_pop_static_delegate)});
     if (efl_ui_stack_insert_before_static_delegate == null)
         efl_ui_stack_insert_before_static_delegate = new efl_ui_stack_insert_before_delegate(insert_before);
     if (methods.FirstOrDefault(m => m.Name == "InsertBefore") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_insert_before"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_insert_before_static_delegate)});
     if (efl_ui_stack_insert_after_static_delegate == null)
         efl_ui_stack_insert_after_static_delegate = new efl_ui_stack_insert_after_delegate(insert_after);
     if (methods.FirstOrDefault(m => m.Name == "InsertAfter") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_insert_after"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_insert_after_static_delegate)});
     if (efl_ui_stack_insert_at_static_delegate == null)
         efl_ui_stack_insert_at_static_delegate = new efl_ui_stack_insert_at_delegate(insert_at);
     if (methods.FirstOrDefault(m => m.Name == "InsertAt") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_insert_at"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_insert_at_static_delegate)});
     if (efl_ui_stack_remove_static_delegate == null)
         efl_ui_stack_remove_static_delegate = new efl_ui_stack_remove_delegate(remove);
     if (methods.FirstOrDefault(m => m.Name == "Remove") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_remove"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_remove_static_delegate)});
     if (efl_ui_stack_remove_at_static_delegate == null)
         efl_ui_stack_remove_at_static_delegate = new efl_ui_stack_remove_at_delegate(remove_at);
     if (methods.FirstOrDefault(m => m.Name == "RemoveAt") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_remove_at"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_remove_at_static_delegate)});
     if (efl_ui_stack_index_get_static_delegate == null)
         efl_ui_stack_index_get_static_delegate = new efl_ui_stack_index_get_delegate(index_get);
     if (methods.FirstOrDefault(m => m.Name == "GetIndex") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_index_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_index_get_static_delegate)});
     if (efl_ui_stack_content_get_static_delegate == null)
         efl_ui_stack_content_get_static_delegate = new efl_ui_stack_content_get_delegate(content_get);
     if (methods.FirstOrDefault(m => m.Name == "GetContent") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_content_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_content_get_static_delegate)});
     if (efl_ui_stack_top_static_delegate == null)
         efl_ui_stack_top_static_delegate = new efl_ui_stack_top_delegate(top);
     if (methods.FirstOrDefault(m => m.Name == "Top") != null)
         descs.Add(new Efl_Op_Description() {api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_stack_top"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_stack_top_static_delegate)});
     descs.AddRange(base.GetEoOps(type));
     return descs;
 }
Exemple #11
0
        public override System.Collections.Generic.List <Efl_Op_Description> GetEoOps(System.Type type)
        {
            var descs   = new System.Collections.Generic.List <Efl_Op_Description>();
            var methods = Efl.Eo.Globals.GetUserMethods(type);

            if (efl_access_value_and_text_get_static_delegate == null)
            {
                efl_access_value_and_text_get_static_delegate = new efl_access_value_and_text_get_delegate(value_and_text_get);
            }
            if (methods.FirstOrDefault(m => m.Name == "GetValueAndText") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_access_value_and_text_get"), func = Marshal.GetFunctionPointerForDelegate(efl_access_value_and_text_get_static_delegate)
                    });
            }
            if (efl_access_value_and_text_set_static_delegate == null)
            {
                efl_access_value_and_text_set_static_delegate = new efl_access_value_and_text_set_delegate(value_and_text_set);
            }
            if (methods.FirstOrDefault(m => m.Name == "SetValueAndText") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_access_value_and_text_set"), func = Marshal.GetFunctionPointerForDelegate(efl_access_value_and_text_set_static_delegate)
                    });
            }
            if (efl_access_value_range_get_static_delegate == null)
            {
                efl_access_value_range_get_static_delegate = new efl_access_value_range_get_delegate(range_get);
            }
            if (methods.FirstOrDefault(m => m.Name == "GetRange") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_access_value_range_get"), func = Marshal.GetFunctionPointerForDelegate(efl_access_value_range_get_static_delegate)
                    });
            }
            if (efl_access_value_increment_get_static_delegate == null)
            {
                efl_access_value_increment_get_static_delegate = new efl_access_value_increment_get_delegate(increment_get);
            }
            if (methods.FirstOrDefault(m => m.Name == "GetIncrement") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_access_value_increment_get"), func = Marshal.GetFunctionPointerForDelegate(efl_access_value_increment_get_static_delegate)
                    });
            }
            if (efl_ui_direction_get_static_delegate == null)
            {
                efl_ui_direction_get_static_delegate = new efl_ui_direction_get_delegate(direction_get);
            }
            if (methods.FirstOrDefault(m => m.Name == "GetDirection") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_direction_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_direction_get_static_delegate)
                    });
            }
            if (efl_ui_direction_set_static_delegate == null)
            {
                efl_ui_direction_set_static_delegate = new efl_ui_direction_set_delegate(direction_set);
            }
            if (methods.FirstOrDefault(m => m.Name == "SetDirection") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_direction_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_direction_set_static_delegate)
                    });
            }
            if (efl_ui_range_value_get_static_delegate == null)
            {
                efl_ui_range_value_get_static_delegate = new efl_ui_range_value_get_delegate(range_value_get);
            }
            if (methods.FirstOrDefault(m => m.Name == "GetRangeValue") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_range_value_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_range_value_get_static_delegate)
                    });
            }
            if (efl_ui_range_value_set_static_delegate == null)
            {
                efl_ui_range_value_set_static_delegate = new efl_ui_range_value_set_delegate(range_value_set);
            }
            if (methods.FirstOrDefault(m => m.Name == "SetRangeValue") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_range_value_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_range_value_set_static_delegate)
                    });
            }
            if (efl_ui_range_min_max_get_static_delegate == null)
            {
                efl_ui_range_min_max_get_static_delegate = new efl_ui_range_min_max_get_delegate(range_min_max_get);
            }
            if (methods.FirstOrDefault(m => m.Name == "GetRangeMinMax") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_range_min_max_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_range_min_max_get_static_delegate)
                    });
            }
            if (efl_ui_range_min_max_set_static_delegate == null)
            {
                efl_ui_range_min_max_set_static_delegate = new efl_ui_range_min_max_set_delegate(range_min_max_set);
            }
            if (methods.FirstOrDefault(m => m.Name == "SetRangeMinMax") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_range_min_max_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_range_min_max_set_static_delegate)
                    });
            }
            if (efl_ui_range_step_get_static_delegate == null)
            {
                efl_ui_range_step_get_static_delegate = new efl_ui_range_step_get_delegate(range_step_get);
            }
            if (methods.FirstOrDefault(m => m.Name == "GetRangeStep") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_range_step_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_range_step_get_static_delegate)
                    });
            }
            if (efl_ui_range_step_set_static_delegate == null)
            {
                efl_ui_range_step_set_static_delegate = new efl_ui_range_step_set_delegate(range_step_set);
            }
            if (methods.FirstOrDefault(m => m.Name == "SetRangeStep") != null)
            {
                descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(_Module.Module, "efl_ui_range_step_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_range_step_set_static_delegate)
                    });
            }
            descs.AddRange(base.GetEoOps(type));
            return(descs);
        }
Exemple #12
0
        private bool PlatformInit()
        {
            WNDCLASS winClass = new WNDCLASS();

            winClass.style         = WinUser.CS_HREDRAW | WinUser.CS_VREDRAW | WinUser.CS_OWNDC;
            proc                   = WndProc;
            winClass.lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(proc);
            winClass.lpszClassName = "Sparky Win32 Window";
            winClass.hCursor       = WinUser.LoadCursorW(IntPtr.Zero, WinUser.IDC_ARROW);
            winClass.hIcon         = WinUser.LoadIconW(IntPtr.Zero, WinUser.IDI_WINLOGO);

            if (WinUser.RegisterClassW(ref winClass) == 0)
            {
                Log.Error("Could not register Win32 class!");
                return(false);
            }

            RECT size = new RECT(0, 0, (int)properties.width, (int)properties.height);

            WinUser.AdjustWindowRectEx(ref size, WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN, false, WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE);

            hWnd = WinUser.CreateWindowExW(WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE,
                                           winClass.lpszClassName, title,
                                           WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN,
                                           (int)(WinUser.GetSystemMetrics(WinUser.SM_CXSCREEN) / 2 - properties.width / 2),
                                           (int)(WinUser.GetSystemMetrics(WinUser.SM_CYSCREEN) / 2 - properties.height / 2),
                                           (int)(size.right + (-size.left)), (int)(size.bottom + (-size.top)), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero
                                           );
            if (hWnd.ToInt32() == 0)
            {
                Log.Error("Could not create window!");
                return(false);
            }

            RegisterWindowClass(hWnd, this);

            hDc = WinUser.GetDC(hWnd);
            PIXELFORMATDESCRIPTOR pfd = GetPixelFormat();
            int pixelFormat           = WinGDI.ChoosePixelFormat(hDc, ref pfd);

            if (pixelFormat != 0)
            {
                if (!WinGDI.SetPixelFormat(hDc, pixelFormat, ref pfd))
                {
                    Log.Error("Failed setting pixel format!");
                    return(false);
                }
            }
            else
            {
                Log.Error("Failed choosing pixel format!");
                return(false);
            }

            Context.Create(properties, hWnd);

            WinUser.ShowWindow(hWnd, WinUser.SW_SHOW);
            WinUser.SetFocus(hWnd);

            return(true);
        }
Exemple #13
0
            /// <summary>Gets the list of Eo operations to override.</summary>
            /// <returns>The list of Eo operations to be overload.</returns>
            public override System.Collections.Generic.List <Efl_Op_Description> GetEoOps(System.Type type)
            {
                var descs   = new System.Collections.Generic.List <Efl_Op_Description>();
                var methods = Efl.Eo.Globals.GetUserMethods(type);

                if (efl_threadio_indata_get_static_delegate == null)
                {
                    efl_threadio_indata_get_static_delegate = new efl_threadio_indata_get_delegate(indata_get);
                }

                if (methods.FirstOrDefault(m => m.Name == "GetIndata") != null)
                {
                    descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_threadio_indata_get"), func = Marshal.GetFunctionPointerForDelegate(efl_threadio_indata_get_static_delegate)
                    });
                }

                if (efl_threadio_indata_set_static_delegate == null)
                {
                    efl_threadio_indata_set_static_delegate = new efl_threadio_indata_set_delegate(indata_set);
                }

                if (methods.FirstOrDefault(m => m.Name == "SetIndata") != null)
                {
                    descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_threadio_indata_set"), func = Marshal.GetFunctionPointerForDelegate(efl_threadio_indata_set_static_delegate)
                    });
                }

                if (efl_threadio_outdata_get_static_delegate == null)
                {
                    efl_threadio_outdata_get_static_delegate = new efl_threadio_outdata_get_delegate(outdata_get);
                }

                if (methods.FirstOrDefault(m => m.Name == "GetOutdata") != null)
                {
                    descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_threadio_outdata_get"), func = Marshal.GetFunctionPointerForDelegate(efl_threadio_outdata_get_static_delegate)
                    });
                }

                if (efl_threadio_outdata_set_static_delegate == null)
                {
                    efl_threadio_outdata_set_static_delegate = new efl_threadio_outdata_set_delegate(outdata_set);
                }

                if (methods.FirstOrDefault(m => m.Name == "SetOutdata") != null)
                {
                    descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_threadio_outdata_set"), func = Marshal.GetFunctionPointerForDelegate(efl_threadio_outdata_set_static_delegate)
                    });
                }

                if (efl_threadio_call_static_delegate == null)
                {
                    efl_threadio_call_static_delegate = new efl_threadio_call_delegate(call);
                }

                if (methods.FirstOrDefault(m => m.Name == "Call") != null)
                {
                    descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_threadio_call"), func = Marshal.GetFunctionPointerForDelegate(efl_threadio_call_static_delegate)
                    });
                }

                if (efl_threadio_call_sync_static_delegate == null)
                {
                    efl_threadio_call_sync_static_delegate = new efl_threadio_call_sync_delegate(call_sync);
                }

                if (methods.FirstOrDefault(m => m.Name == "CallSync") != null)
                {
                    descs.Add(new Efl_Op_Description()
                    {
                        api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_threadio_call_sync"), func = Marshal.GetFunctionPointerForDelegate(efl_threadio_call_sync_static_delegate)
                    });
                }

                return(descs);
            }
Exemple #14
0
 public void AddServerCommand(string cmd_name, functionServerCommand functionPointer)
 {
     ef.AddServerCommand(cmd_name, Marshal.GetFunctionPointerForDelegate(functionPointer));
 }
Exemple #15
0
        public static void tolua_pushcfunction(IntPtr luaState, LuaCSFunction func)
        {
            IntPtr fn = Marshal.GetFunctionPointerForDelegate(func);

            tolua_pushcfunction(luaState, fn);
        }
        /// <summary>
        /// Initialize the TextInput with the given GameWindow.
        /// </summary>
        /// <param name="window">The XNA window to which text input should be linked.</param>
        public static void Initialize(GameWindow window)
        {
            if (initialized)
            {
                throw new InvalidOperationException("TextInput.Initialize can only be called once!");
            }

            hookProcDelegate = new WndProc(HookProc);
            prevWndProc      = (IntPtr)SetWindowLong(window.Handle, GWL_WNDPROC, (int)Marshal.GetFunctionPointerForDelegate(hookProcDelegate));

            hIMC        = ImmGetContext(window.Handle);
            initialized = true;
        }
Exemple #17
0
        public static IntPtr tolua_atpanic(IntPtr L, LuaCSFunction func)
        {
            IntPtr fn = Marshal.GetFunctionPointerForDelegate(func);

            return(lua_atpanic(L, fn));
        }
Exemple #18
0
        /// <summary>
        /// <para>Registers a callback for the LibVLC exit event. This is mostly useful if</para>
        /// <para>the VLC playlist and/or at least one interface are started with</para>
        /// <para>libvlc_playlist_play() or libvlc_add_intf() respectively.</para>
        /// <para>Typically, this function will wake up your application main loop (from</para>
        /// <para>another thread).</para>
        /// </summary>
        /// <param name="cb">
        /// <para>callback to invoke when LibVLC wants to exit,</para>
        /// <para>or NULL to disable the exit handler (as by default)</para>
        /// </param>
        /// <param name="opaque">data pointer for the callback</param>
        /// <remarks>
        /// <para>This function should be called before the playlist or interface are</para>
        /// <para>started. Otherwise, there is a small race condition: the exit event could</para>
        /// <para>be raised before the handler is registered.</para>
        /// <para>This function and libvlc_wait() cannot be used at the same time.</para>
        /// </remarks>
        public void SetExitHandler(ExitCallback cb, IntPtr opaque)
        {
            var cbFunctionPointer = cb == null ? IntPtr.Zero : Marshal.GetFunctionPointerForDelegate(cb);

            Native.LibVLCSetExitHandler(NativeReference, cbFunctionPointer, opaque);
        }
Exemple #19
0
        /// <summary>
        ///  Constructor.
        /// </summary>
        /// <param name="className">Name, or default will be generated.</param>
        /// <param name="moduleInstance">Module to associate with the window. The entry assembly is the default.</param>
        /// <param name="backgroundBrush">Use (IntPtr)(-1) for no background brush.</param>
        /// <param name="icon">Use (IntPtr)(-1) for no icon.</param>
        /// <param name="cursor">Use (IntPtr)(-1) for no cursor.</param>
        /// <param name="menuName">Menu name, can not set with <paramref name="menuId"/>.</param>
        /// <param name="menuId">Menu id, can not set with <paramref name="menuName"/>.</param>
        public unsafe WindowClass(
            string className             = default,
            IntPtr moduleInstance        = default,
            User32.CS classStyle         = User32.CS.HREDRAW | User32.CS.VREDRAW,
            Gdi32.HBRUSH backgroundBrush = default,
            IntPtr icon          = default,
            IntPtr cursor        = default,
            string menuName      = null,
            int menuId           = 0,
            int classExtraBytes  = 0,
            int windowExtraBytes = 0)
        {
            // Handle default values
            className ??= Guid.NewGuid().ToString();

            if (backgroundBrush.IsNull)
            {
                backgroundBrush = User32.GetSysColorBrush(User32.COLOR.WINDOW);
            }
            else if (backgroundBrush.Handle == (IntPtr)(-1))
            {
                backgroundBrush = default;
            }

            if (icon == default)
            {
                icon = LoadIconW(IntPtr.Zero, (IntPtr)IDI_APPLICATION);
            }
            else if (icon == (IntPtr)(-1))
            {
                icon = default;
            }

            if (cursor == default)
            {
                cursor = User32.LoadCursorW(IntPtr.Zero, (IntPtr)User32.CursorResourceId.IDC_ARROW);
            }
            else if (cursor == (IntPtr)(-1))
            {
                cursor = default;
            }

            if (moduleInstance == IntPtr.Zero)
            {
                Marshal.GetHINSTANCE(Assembly.GetCallingAssembly().Modules.First());
            }

            if (menuId != 0 && menuName != null)
            {
                throw new ArgumentException($"Can't set both {nameof(menuName)} and {nameof(menuId)}.");
            }

            _windowProcedure = WNDPROC;
            ModuleInstance   = moduleInstance;

            _className = className;
            _menuName  = menuName ?? string.Empty;

            _wndClass = new User32.WNDCLASS
            {
                style         = classStyle,
                lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(_windowProcedure),
                cbClsExtra    = classExtraBytes,
                cbWndExtra    = windowExtraBytes,
                hInstance     = moduleInstance,
                hIcon         = icon,
                hCursor       = cursor,
                hbrBackground = backgroundBrush,
                lpszMenuName  = (char *)menuId
            };
        }
Exemple #20
0
 public FunctionPointer(Delegate @delegate)
 {
     _ptr = Marshal.GetFunctionPointerForDelegate(@delegate);
 }
        void Awake()
        {
            // Debug.Log("::::::::::::::::::::::::::::::::::::::");

#if UNITY_EDITOR
            EditorPlayMode.PlayModeChanged += OnPlayModeChanged;
#endif

            Init();

            if (Application.platform.ToString().StartsWith("OSX"))
            {
                OnPixelBufferError += (mpmp) => { Load(); };
            }

            /*
             * OnTextureChanged += (mpmp) => {
             * // _UpdateTextureFromNative();
             * // _UpdateNativeVideoSize();
             * //  Vector2 size = mpmp.GetNativeVideoSize();
             * //  Debug.Log("OnTextureChanged:"+ size);
             *
             * };
             *
             * OnLoaded += (mpmp) =>
             * {
             *  Debug.Log("OnLoaded");
             * };
             */

            SetUpdateFrequency(_updateFrequency);



            if (_isOnWindows && _isOnWindows7)
            {
                return;                               // yield break;
            }
            // RenderEventFunc = GetRenderEventFunc();

#if !(UNITY_WEBGL && !UNITY_EDITOR)
            RenderEventFunc = MPMP_GetRenderEventFunc();
#endif



#if ((UNITY_STANDALONE_WIN && !UNITY_EDITOR_OSX) || UNITY_EDITOR_WIN)
            //Setup the debug callback system for Windows---

#if MPMP_DEBUG
            //http://www.gamedev.net/page/resources/_/technical/game-programming/c-plugin-debug-log-with-unity-r3349

            NativeCallbackDebugDelegate callbackDebug_delegate = new NativeCallbackDebugDelegate(CallbackNativeDebug);
            _handleNativeCallbackDebug = GCHandle.Alloc(callbackDebug_delegate, GCHandleType.Pinned);
            // Convert callback_delegate into a function pointer that can be used in unmanaged code.
            _intptr_NativeCallbackDebug_delegate = Marshal.GetFunctionPointerForDelegate(callbackDebug_delegate);

            // Call the API passing along the function pointer.
            MPMP_SetDebugFunction(_intptr_NativeCallbackDebug_delegate);


            try {
                if (!MPMP_IsMEPlayerInitialized())
                {
                    Debug.Log("InitDebugConsole");
                    MPMP_InitDebugConsole();
                }
            }
            catch (Exception e)
            {
                Debug.Log("EXCEPTION:" + e.Message);
            }
#endif


            MPMP_UnityPluginInit();//Set the Unity graphics device in the native plugin
#endif //Windows



#if UNITY_ANDROID && !UNITY_EDITOR
            AndroidJavaClass  unity_jc    = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject activity_jo = unity_jc.GetStatic <AndroidJavaObject>("currentActivity");


            AndroidJavaObject mpmp_jo = new AndroidJavaObject("org.monoflow.media.MPMP", activity_jo);
            //AndroidJavaClass mpmp_jc = new AndroidJavaClass("org.monoflow.media.MPMP");

            _id = mpmp_jo.Call <int>("GetId");
#else
            //Windows,Editor,iOS

            ColorSpace cs = QualitySettings.activeColorSpace;

            bool isLinear = (cs == ColorSpace.Linear);

            //There are some issues with dual graphic card setups/ NVIDIA and linear colorspace so we can force to use always RGB textures on the native side. But this will cause not accurate texture colors!
            if (forceGamma)
            {
                isLinear = false;
            }
            _id = MPMP_New(isLinear); //Create the native player
#endif
            // Debug.Log("ID:" + _id);


            if (!_instances.ContainsKey(_id))
            {
                _instances.Add(_id, this);
            }



            //Setup the callback system-----------------------

            // Call the API passing along the function pointer.
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || (UNITY_IPHONE && !UNITY_EDITOR_WIN)
            MPMP_SetCallbackFunction(_id, CallBackNativeAOT);
#else
            //-------
#if UNITY_WEBGL && !UNITY_EDITOR
            // SetCallbackFunction(WebGLCallbackFunc);
            MPMP_SetCallbackFunction(_id, CallBackNativeAOT);
#else
            NativeCallbackDelegate _callback_delegate = new NativeCallbackDelegate(CallBackNative);
            _handleNativeCallback = GCHandle.Alloc(_callback_delegate, GCHandleType.Pinned);
            // Convert callback_delegate into a function pointer that can be used in unmanaged code.
            _intptr_NativeCallback_delegate = Marshal.GetFunctionPointerForDelegate(_callback_delegate);

            MPMP_SetCallbackFunction(_id, _intptr_NativeCallback_delegate);
#endif
            //---------
#endif


            //--------------------------------------

            MPMP_SetAutoPlay(_id, autoPlay);
            MPMP_SetLooping(_id, looping);
            MPMP_SetVolume(_id, _volume);

#if (UNITY_ANDROID && !UNITY_EDITOR)
            Debug.Log("Application.dataPath: " + Application.dataPath);
            Debug.Log("Application.streamingAssetsPath: " + Application.streamingAssetsPath);
            if (Application.dataPath.Contains(".obb") || Application.dataPath.Contains("/base.apk"))
            {
                SetOBBPath(_id, Application.dataPath);
            }
            //SetOBBPath(_id,Application.dataPath);//DEBUG

            GL.IssuePluginEvent(RenderEventFunc, _id); //Trigger the OpenGL Initializing
#endif



#if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || (UNITY_IPHONE && !UNITY_EDITOR_WIN)) && MPMP_DEBUG
            _ext2_SetLogCallback(_id, NativeCallbackFunc);
#endif

            _UpdateStatus();

            //Unity 5.3 bug with multiple instances of this script .Normal Update interval is used!
            //yield return StartCoroutine(_Update());

            /*
             * yield return new WaitForEndOfFrame();//One frame delay to be sure that all stuff is initialized on the native site
             * if (OnInit != null) OnInit(this);
             *
             * yield break;
             */
        }
Exemple #22
0
                /// <summary>Gets the list of Eo operations to override.</summary>
                /// <returns>The list of Eo operations to be overload.</returns>
                public override System.Collections.Generic.List <Efl_Op_Description> GetEoOps(System.Type type)
                {
                    var descs   = new System.Collections.Generic.List <Efl_Op_Description>();
                    var methods = Efl.Eo.Globals.GetUserMethods(type);

                    if (efl_ui_drag_value_get_static_delegate == null)
                    {
                        efl_ui_drag_value_get_static_delegate = new efl_ui_drag_value_get_delegate(drag_value_get);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "GetDragValue") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_value_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_value_get_static_delegate)
                        });
                    }

                    if (efl_ui_drag_value_set_static_delegate == null)
                    {
                        efl_ui_drag_value_set_static_delegate = new efl_ui_drag_value_set_delegate(drag_value_set);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "SetDragValue") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_value_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_value_set_static_delegate)
                        });
                    }

                    if (efl_ui_drag_size_get_static_delegate == null)
                    {
                        efl_ui_drag_size_get_static_delegate = new efl_ui_drag_size_get_delegate(drag_size_get);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "GetDragSize") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_size_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_size_get_static_delegate)
                        });
                    }

                    if (efl_ui_drag_size_set_static_delegate == null)
                    {
                        efl_ui_drag_size_set_static_delegate = new efl_ui_drag_size_set_delegate(drag_size_set);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "SetDragSize") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_size_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_size_set_static_delegate)
                        });
                    }

                    if (efl_ui_drag_dir_get_static_delegate == null)
                    {
                        efl_ui_drag_dir_get_static_delegate = new efl_ui_drag_dir_get_delegate(drag_dir_get);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "GetDragDir") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_dir_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_dir_get_static_delegate)
                        });
                    }

                    if (efl_ui_drag_step_get_static_delegate == null)
                    {
                        efl_ui_drag_step_get_static_delegate = new efl_ui_drag_step_get_delegate(drag_step_get);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "GetDragStep") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_step_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_step_get_static_delegate)
                        });
                    }

                    if (efl_ui_drag_step_set_static_delegate == null)
                    {
                        efl_ui_drag_step_set_static_delegate = new efl_ui_drag_step_set_delegate(drag_step_set);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "SetDragStep") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_step_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_step_set_static_delegate)
                        });
                    }

                    if (efl_ui_drag_page_get_static_delegate == null)
                    {
                        efl_ui_drag_page_get_static_delegate = new efl_ui_drag_page_get_delegate(drag_page_get);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "GetDragPage") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_page_get"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_page_get_static_delegate)
                        });
                    }

                    if (efl_ui_drag_page_set_static_delegate == null)
                    {
                        efl_ui_drag_page_set_static_delegate = new efl_ui_drag_page_set_delegate(drag_page_set);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "SetDragPage") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_page_set"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_page_set_static_delegate)
                        });
                    }

                    if (efl_ui_drag_step_move_static_delegate == null)
                    {
                        efl_ui_drag_step_move_static_delegate = new efl_ui_drag_step_move_delegate(drag_step_move);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "MoveDragStep") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_step_move"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_step_move_static_delegate)
                        });
                    }

                    if (efl_ui_drag_page_move_static_delegate == null)
                    {
                        efl_ui_drag_page_move_static_delegate = new efl_ui_drag_page_move_delegate(drag_page_move);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "MoveDragPage") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_ui_drag_page_move"), func = Marshal.GetFunctionPointerForDelegate(efl_ui_drag_page_move_static_delegate)
                        });
                    }

                    return(descs);
                }
Exemple #23
0
 protected BroadphaseAabbCallback()
 {
     _process = ProcessUnmanaged;
     _native  = btBroadphaseAabbCallbackWrapper_new(
         Marshal.GetFunctionPointerForDelegate(_process));
 }
Exemple #24
0
        public void Load()
        {
            _recv              = OnPluginRecv;
            _send              = OnPluginSend;
            _recv_new          = OnPluginRecv_new;
            _send_new          = OnPluginSend_new;
            _getPacketLength   = PacketsTable.GetPacketLength;
            _getPlayerPosition = GetPlayerPosition;
            _castSpell         = GameActions.CastSpell;
            _getStaticImage    = GetStaticImage;
            _getUoFilePath     = GetUOFilePath;
            _requestMove       = RequestMove;
            _setTitle          = SetWindowTitle;
            _get_static_data   = GetStaticData;
            _get_tile_data     = GetTileData;
            _get_cliloc        = GetCliloc;

            SDL.SDL_SysWMinfo info = new SDL.SDL_SysWMinfo();
            SDL.SDL_VERSION(out info.version);
            SDL.SDL_GetWindowWMInfo(Client.Game.Window.Handle, ref info);

            IntPtr hwnd = IntPtr.Zero;

            if (info.subsystem == SDL.SDL_SYSWM_TYPE.SDL_SYSWM_WINDOWS)
            {
                hwnd = info.info.win.window;
            }

            PluginHeader header = new PluginHeader
            {
                ClientVersion     = (int)Client.Version,
                Recv              = Marshal.GetFunctionPointerForDelegate(_recv),
                Send              = Marshal.GetFunctionPointerForDelegate(_send),
                GetPacketLength   = Marshal.GetFunctionPointerForDelegate(_getPacketLength),
                GetPlayerPosition = Marshal.GetFunctionPointerForDelegate(_getPlayerPosition),
                CastSpell         = Marshal.GetFunctionPointerForDelegate(_castSpell),
                GetStaticImage    = Marshal.GetFunctionPointerForDelegate(_getStaticImage),
                HWND              = hwnd,
                GetUOFilePath     = Marshal.GetFunctionPointerForDelegate(_getUoFilePath),
                RequestMove       = Marshal.GetFunctionPointerForDelegate(_requestMove),
                SetTitle          = Marshal.GetFunctionPointerForDelegate(_setTitle),
                Recv_new          = Marshal.GetFunctionPointerForDelegate(_recv_new),
                Send_new          = Marshal.GetFunctionPointerForDelegate(_send_new),

                SDL_Window    = Client.Game.Window.Handle,
                GetStaticData = Marshal.GetFunctionPointerForDelegate(_get_static_data),
                GetTileData   = Marshal.GetFunctionPointerForDelegate(_get_tile_data),
                GetCliloc     = Marshal.GetFunctionPointerForDelegate(_get_cliloc),
            };

            void *func = &header;

            if (Environment.OSVersion.Platform != PlatformID.Unix && Environment.OSVersion.Platform != PlatformID.MacOSX)
            {
                UnblockPath(Path.GetDirectoryName(_path));
            }

            try
            {
                IntPtr assptr = Native.LoadLibrary(_path);

                Log.Trace($"assembly: {assptr}");

                if (assptr == IntPtr.Zero)
                {
                    throw new Exception("Invalid Assembly, Attempting managed load.");
                }

                Log.Trace($"Searching for 'Install' entry point  -  {assptr}");

                IntPtr installPtr = Native.GetProcessAddress(assptr, "Install");

                Log.Trace($"Entry point: {installPtr}");

                if (installPtr == IntPtr.Zero)
                {
                    throw new Exception("Invalid Entry Point, Attempting managed load.");
                }

                Marshal.GetDelegateForFunctionPointer <OnInstall>(installPtr)(func);

                Console.WriteLine(">>> ADDRESS {0}", header.OnInitialize);
            }
            catch
            {
                try
                {
                    var asm  = Assembly.LoadFile(_path);
                    var type = asm.GetType("Assistant.Engine");

                    if (type == null)
                    {
                        Log.Error(
                            "Unable to find Plugin Type, API requires the public class Engine in namespace Assistant.");

                        return;
                    }

                    var meth = type.GetMethod("Install", BindingFlags.Public | BindingFlags.Static);

                    if (meth == null)
                    {
                        Log.Error("Engine class missing public static Install method Needs 'public static unsafe void Install(PluginHeader *plugin)' ");

                        return;
                    }

                    meth.Invoke(null, new object[] { (IntPtr)func });
                }
                catch (Exception err)
                {
                    Log.Error(
                        $"Plugin threw an error during Initialization. {err.Message} {err.StackTrace} {err.InnerException?.Message} {err.InnerException?.StackTrace}");

                    return;
                }
            }


            if (header.OnRecv != IntPtr.Zero)
            {
                _onRecv = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(header.OnRecv);
            }

            if (header.OnSend != IntPtr.Zero)
            {
                _onSend = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(header.OnSend);
            }

            if (header.OnHotkeyPressed != IntPtr.Zero)
            {
                _onHotkeyPressed = Marshal.GetDelegateForFunctionPointer <OnHotkey>(header.OnHotkeyPressed);
            }

            if (header.OnMouse != IntPtr.Zero)
            {
                _onMouse = Marshal.GetDelegateForFunctionPointer <OnMouse>(header.OnMouse);
            }

            if (header.OnPlayerPositionChanged != IntPtr.Zero)
            {
                _onUpdatePlayerPosition = Marshal.GetDelegateForFunctionPointer <OnUpdatePlayerPosition>(header.OnPlayerPositionChanged);
            }

            if (header.OnClientClosing != IntPtr.Zero)
            {
                _onClientClose = Marshal.GetDelegateForFunctionPointer <OnClientClose>(header.OnClientClosing);
            }

            if (header.OnInitialize != IntPtr.Zero)
            {
                _onInitialize = Marshal.GetDelegateForFunctionPointer <OnInitialize>(header.OnInitialize);
            }

            if (header.OnConnected != IntPtr.Zero)
            {
                _onConnected = Marshal.GetDelegateForFunctionPointer <OnConnected>(header.OnConnected);
            }

            if (header.OnDisconnected != IntPtr.Zero)
            {
                _onDisconnected = Marshal.GetDelegateForFunctionPointer <OnDisconnected>(header.OnDisconnected);
            }

            if (header.OnFocusGained != IntPtr.Zero)
            {
                _onFocusGained = Marshal.GetDelegateForFunctionPointer <OnFocusGained>(header.OnFocusGained);
            }

            if (header.OnFocusLost != IntPtr.Zero)
            {
                _onFocusLost = Marshal.GetDelegateForFunctionPointer <OnFocusLost>(header.OnFocusLost);
            }

            if (header.Tick != IntPtr.Zero)
            {
                _tick = Marshal.GetDelegateForFunctionPointer <OnTick>(header.Tick);
            }


            if (header.OnRecv_new != IntPtr.Zero)
            {
                _onRecv_new = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv_new>(header.OnRecv_new);
            }
            if (header.OnSend_new != IntPtr.Zero)
            {
                _onSend_new = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv_new>(header.OnSend_new);
            }

            if (header.OnDrawCmdList != IntPtr.Zero)
            {
                _draw_cmd_list = Marshal.GetDelegateForFunctionPointer <OnDrawCmdList>(header.OnDrawCmdList);
            }
            if (header.OnWndProc != IntPtr.Zero)
            {
                _on_wnd_proc = Marshal.GetDelegateForFunctionPointer <OnWndProc>(header.OnWndProc);
            }


            IsValid = true;

            _onInitialize?.Invoke();
        }
        public static void lua_pushstdcallcfunction(IntPtr luaState, LuaCSFunction func)
        {
            IntPtr fn = Marshal.GetFunctionPointerForDelegate(func);

            lua_pushcclosure(luaState, fn, 0);
        }
        /// <summary>
        /// Helper method that does the core instantiation & initialization of face tracking engine
        /// </summary>
        /// <param name="newColorCameraConfig">Color camera configuration</param>
        /// <param name="newDepthCameraConfig">Depth camera configuration</param>
        /// <param name="colorImagePtr">Allows face tracking engine to read color image from native memory pointer.
        /// If set to IntPtr.Zero, image data needs to be provided for tracking to this instance. </param>
        /// <param name="depthImagePtr">Allows face tracking engine to read depth image from native memory pointer.
        /// If set to IntPtr.Zero, image data needs to be provided for tracking to this instance.</param>
        /// <param name="newRegisterDepthToColorDelegate">Callback which maps of depth to color pixels</param>
        private void Initialize(
            CameraConfig newColorCameraConfig,
            CameraConfig newDepthCameraConfig,
            IntPtr colorImagePtr,
            IntPtr depthImagePtr,
            FaceTrackingRegisterDepthToColor newRegisterDepthToColorDelegate)
        {
            if (newColorCameraConfig == null)
            {
                throw new ArgumentNullException("newColorCameraConfig");
            }

            if (newDepthCameraConfig == null)
            {
                throw new ArgumentNullException("newDepthCameraConfig");
            }

            if (newRegisterDepthToColorDelegate == null)
            {
                throw new ArgumentNullException("newRegisterDepthToColorDelegate");
            }

            // initialize perf counters
            this.totalTracks = 0;
            this.trackStopwatch.Reset();

            // get configuration & trace settings
            this.traceLevel = new TraceSwitch(FaceTrackTraceSwitchName, FaceTrackTraceSwitchName).Level;

            this.videoCameraConfig            = newColorCameraConfig;
            this.depthCameraConfig            = newDepthCameraConfig;
            this.registerDepthToColorDelegate = newRegisterDepthToColorDelegate;

            this.faceTrackerInteropPtr = NativeMethods.FTCreateFaceTracker(IntPtr.Zero);
            if (this.faceTrackerInteropPtr == null)
            {
                throw new InsufficientMemoryException("Cannot create face tracker.");
            }

            IntPtr funcPtr = Marshal.GetFunctionPointerForDelegate(this.registerDepthToColorDelegate);

            if (funcPtr == IntPtr.Zero)
            {
                throw new InsufficientMemoryException("Cannot setup callback for retrieving color to depth pixel mapping");
            }

            int hr = this.faceTrackerInteropPtr.Initialize(this.videoCameraConfig, this.depthCameraConfig, funcPtr, null);

            if (hr != 0)
            {
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture, "Failed to initialize face tracker - Error code from native=0x{0:X}", hr));
            }

            this.frame = this.CreateResult(out hr);
            if (this.frame == null || hr != 0)
            {
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture, "Failed to create face tracking result. Error code from native=0x{0:X}", hr));
            }

            this.colorFaceTrackingImage = new Image();
            if (colorImagePtr == IntPtr.Zero)
            {
                this.colorFaceTrackingImage.Allocate(
                    this.videoCameraConfig.Width, this.videoCameraConfig.Height, this.videoCameraConfig.ImageFormat);
            }
            else
            {
                this.colorFaceTrackingImage.Attach(
                    this.videoCameraConfig.Width,
                    this.videoCameraConfig.Height,
                    colorImagePtr,
                    this.videoCameraConfig.ImageFormat,
                    this.videoCameraConfig.Stride);
            }

            this.depthFaceTrackingImage = new Image();
            if (depthImagePtr == IntPtr.Zero)
            {
                this.depthFaceTrackingImage.Allocate(
                    this.depthCameraConfig.Width, this.depthCameraConfig.Height, this.depthCameraConfig.ImageFormat);
            }
            else
            {
                this.depthFaceTrackingImage.Attach(
                    this.depthCameraConfig.Width,
                    this.depthCameraConfig.Height,
                    depthImagePtr,
                    this.depthCameraConfig.ImageFormat,
                    this.depthCameraConfig.Stride);
            }
        }
Exemple #27
0
        public void SetFreeCallback(PacketFreeCallback callback)
        {
            ThrowIfNotCreated();

            Native.enet_packet_set_free_callback(nativePacket, Marshal.GetFunctionPointerForDelegate(callback));
        }
Exemple #28
0
                /// <summary>Gets the list of Eo operations to override.</summary>
                /// <returns>The list of Eo operations to be overload.</returns>
                public override System.Collections.Generic.List <Efl_Op_Description> GetEoOps(System.Type type)
                {
                    var descs   = new System.Collections.Generic.List <Efl_Op_Description>();
                    var methods = Efl.Eo.Globals.GetUserMethods(type);

                    if (efl_io_reader_can_read_get_static_delegate == null)
                    {
                        efl_io_reader_can_read_get_static_delegate = new efl_io_reader_can_read_get_delegate(can_read_get);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "GetCanRead") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_can_read_get"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_can_read_get_static_delegate)
                        });
                    }

                    if (efl_io_reader_can_read_set_static_delegate == null)
                    {
                        efl_io_reader_can_read_set_static_delegate = new efl_io_reader_can_read_set_delegate(can_read_set);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "SetCanRead") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_can_read_set"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_can_read_set_static_delegate)
                        });
                    }

                    if (efl_io_reader_eos_get_static_delegate == null)
                    {
                        efl_io_reader_eos_get_static_delegate = new efl_io_reader_eos_get_delegate(eos_get);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "GetEos") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_eos_get"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_eos_get_static_delegate)
                        });
                    }

                    if (efl_io_reader_eos_set_static_delegate == null)
                    {
                        efl_io_reader_eos_set_static_delegate = new efl_io_reader_eos_set_delegate(eos_set);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "SetEos") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_eos_set"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_eos_set_static_delegate)
                        });
                    }

                    if (efl_io_reader_read_static_delegate == null)
                    {
                        efl_io_reader_read_static_delegate = new efl_io_reader_read_delegate(read);
                    }

                    if (methods.FirstOrDefault(m => m.Name == "Read") != null)
                    {
                        descs.Add(new Efl_Op_Description()
                        {
                            api_func = Efl.Eo.FunctionInterop.LoadFunctionPointer(Module.Module, "efl_io_reader_read"), func = Marshal.GetFunctionPointerForDelegate(efl_io_reader_read_static_delegate)
                        });
                    }

                    return(descs);
                }
Exemple #29
0
        public void SetChecksumCallback(ChecksumCallback callback)
        {
            ThrowIfNotCreated();

            Native.enet_host_set_checksum_callback(nativeHost, Marshal.GetFunctionPointerForDelegate(callback));
        }
Exemple #30
0
        /// <summary>
        ///     Creates a program from the provided source codes asynchronously. The program is created, compiled, and linked.
        /// </summary>
        /// <param name="sources">The source codes from which the program is to be created.</param>
        /// <exception cref="OpenClException">
        ///     If the program could not be created, compiled, or linked, then an
        ///     <see cref="OpenClException" /> is thrown.
        /// </exception>
        /// <returns>Returns the created program.</returns>
        public Task <Program> CreateAndBuildProgramFromStringAsync(IEnumerable <string> sources)
        {
            // Creates a new task completion source, which is used to signal when the build has completed
            TaskCompletionSource <Program> taskCompletionSource = new TaskCompletionSource <Program>();

            // Loads the program from the specified source string
            IntPtr[] sourceList     = sources.Select(source => Marshal.StringToHGlobalAnsi(source)).ToArray();
            uint[]   sourceLengths  = sources.Select(source => (uint)source.Length).ToArray();
            IntPtr   programPointer =
                ProgramsNativeApi.CreateProgramWithSource(Handle, 1, sourceList, sourceLengths, out Result result);

            // Checks if the program creation was successful, if not, then an exception is thrown
            if (result != Result.Success)
            {
                throw new OpenClException("The program could not be created.", result);
            }

            // Builds (compiles and links) the program and checks if it was successful, if not, then an exception is thrown
            Result result1 = result;

            result = ProgramsNativeApi.BuildProgram(
                programPointer,
                0,
                null,
                null,
                Marshal.GetFunctionPointerForDelegate(
                    new BuildProgramCallback(
                        (
                            builtProgramPointer,
                            userData) =>
            {
                // Tries to validate the build, if not successful, then an exception is thrown
                try
                {
                    // Cycles over all devices and retrieves the build log for each one, so that the errors that occurred can be added to the exception message (if any error occur during the retrieval, the exception is thrown without the log)
                    Dictionary
                    <string
                     , string
                    > buildLogs
                        = new
                          Dictionary
                          <string
                           , string
                          >();
                    foreach
                    (Device
                     device
                     in
                     Devices
                    )
                    {
                        try
                        {
                            string
                            buildLog
                                = GetProgramBuildInformation
                                  <string
                                  >(
                                      builtProgramPointer,
                                      device,
                                      ProgramBuildInformation
                                      .Log
                                      ).Trim();
                            if
                            (!string
                             .IsNullOrWhiteSpace(
                                 buildLog
                                 ))
                            {
                                buildLogs
                                .Add(
                                    device
                                    .Name,
                                    buildLog
                                    );
                            }
                        }
                        catch
                        (OpenClException
                        )
                        {
                        }
                    }

                    // Checks if there were any errors, if so then the build logs are compiled into a formatted string and integrates it into the exception message
                    if
                    (buildLogs
                     .Any()
                    )
                    {
                        string
                        buildLogString
                            = string
                              .Join(
                                  $"{Environment.NewLine}{Environment.NewLine}",
                                  buildLogs
                                  .Select(
                                      keyValuePair =>
                                      $" Build log for device \"{keyValuePair.Key}\":{Environment.NewLine}{keyValuePair.Value}"
                                      )
                                  );
                        taskCompletionSource
                        .TrySetException(
                            new
                            OpenClException(
                                $"The program could not be compiled and linked.{Environment.NewLine}{Environment.NewLine}{buildLogString}",
                                result1
                                )
                            );
                    }

                    // Since the build was successful, the program is created and the task completion source is resolved with it Creates the new program and returns it
                    taskCompletionSource
                    .TrySetResult(
                        new
                        Program(
                            builtProgramPointer
                            )
                        );
                }
                catch
                (Exception
                 exception
                )
                {
                    taskCompletionSource
                    .TrySetException(
                        exception
                        );
                }
            }
                        )
                    ),
                IntPtr.Zero
                );

            // Checks if the build could be started successfully, if not, then an exception is thrown
            if (result != Result.Success)
            {
                if (result != Result.Success)
                {
                    taskCompletionSource.TrySetException(
                        new OpenClException(
                            "The program could not be compiled and linked.",
                            result
                            )
                        );
                }
            }

            // Returns the task which is resolved when the program was build successful or not
            return(taskCompletionSource.Task);
        }