// Called by the EasyHook API. This method will keep running untill the connection to the program is stopped.
        public void Run(RemoteHooking.IContext context, String channelName, IntPtr hWnd)
        {
            try
            {
                // Hook the DirectX API.
                directXHook = new DXHookD3D9(chatInterface);
                directXHook.Hook(hWnd);
            }
            catch (Exception)
            {
                return;
            }

            try
            {
                while (true)
                {
                    // Check for new events every 100 millis.
                    Thread.Sleep(100);

                    // Parse all the pending events.
                    object[] pendingEvent;
                    while ((pendingEvent = chatInterface.GetPendingEvent()) != null)
                    {
                        // Handle the event and perform the specified action.
                        int type = (int)pendingEvent[0];
                        switch (type)
                        {
                            // Message
                            case 0:
                                String sender = (String)pendingEvent[1];
                                String message = (String)pendingEvent[2];

                                directXHook.Messages.Add(new DXHookD3D9.Message(sender, message));

                                break;
                            // Hide / Show
                            case 1:
                                Boolean hide = (Boolean)pendingEvent[1];

                                directXHook.Hide = hide;

                                break;
                            // Setting change
                            case 2:
                                String fieldName = (String)pendingEvent[1];

                                FieldInfo info = typeof(DXHookD3D9).GetField(fieldName);
                                info.SetValue(directXHook, pendingEvent[2]);

                                break;
                        }
                    }

                    // Make sure we're still connected.
                    chatInterface.Ping();
                }
            }
            catch
            {
                // Ping() will raise an exception if host is unreachable.
            }
            finally
            {
                try
                {
                    // Un-register DirectX hooks, clean up variables.
                    directXHook.Cleanup();
                }
                catch
                {
                }
            }
        }
示例#2
0
        // Called by the EasyHook API. This method will keep running untill the connection to the program is stopped.
        public void Run(RemoteHooking.IContext context, String channelName, IntPtr hWnd)
        {
            try
            {
                // Hook the DirectX API.
                directXHook = new DXHookD3D9(chatInterface);
                directXHook.Hook(hWnd);
            }
            catch (Exception)
            {
                return;
            }

            try
            {
                while (true)
                {
                    // Check for new events every 100 millis.
                    Thread.Sleep(100);

                    // Parse all the pending events.
                    object[] pendingEvent;
                    while ((pendingEvent = chatInterface.GetPendingEvent()) != null)
                    {
                        // Handle the event and perform the specified action.
                        int type = (int)pendingEvent[0];
                        switch (type)
                        {
                        // Message
                        case 0:
                            String sender  = (String)pendingEvent[1];
                            String message = (String)pendingEvent[2];

                            directXHook.Messages.Add(new DXHookD3D9.Message(sender, message));

                            break;

                        // Hide / Show
                        case 1:
                            Boolean hide = (Boolean)pendingEvent[1];

                            directXHook.Hide = hide;

                            break;

                        // Setting change
                        case 2:
                            String fieldName = (String)pendingEvent[1];

                            FieldInfo info = typeof(DXHookD3D9).GetField(fieldName);
                            info.SetValue(directXHook, pendingEvent[2]);

                            break;
                        }
                    }

                    // Make sure we're still connected.
                    chatInterface.Ping();
                }
            }
            catch
            {
                // Ping() will raise an exception if host is unreachable.
            }
            finally
            {
                try
                {
                    // Un-register DirectX hooks, clean up variables.
                    directXHook.Cleanup();
                }
                catch
                {
                }
            }
        }