试图为C#中的在线游戏mmorpg编写机器人 [英] trying to write a bot for online games mmorpg in C#

查看:56
本文介绍了试图为C#中的在线游戏mmorpg编写机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试为在线游戏编写机器人,在我的任务的这个阶段是确定怪物的颜色,将鼠标悬停在它上面并按下双击。所有这些我都学会了在桌面上做的事情,通过创建一个循环遍历像素的循环,之后鼠标在这个像素上移动读取颜色,如果满足两次点击。但是只要鼠标进入游戏窗口,它只是pereprygivaet.Ya理解为什么会发生这种情况,因为游戏是由自己的代码控制的,但我仍然可以在游戏中控制鼠标?我只是在第一次写的东西...我想在C#中找到解决方案





Trying to write a bot for online games, at this stage of my task is to determine the color of the monster , hover over it and pressing a double click . All this I learned to do on the desktop by means of creating a loop that iterates through the pixels after which the mouse moves over this pixel reads color and if satisfies twice clicks in place. But as soon as the mouse comes to the game window it simply pereprygivaet.Ya understand is why this is happening because the game is controlled by its own code , but I can still control the mouse in the game? I was just in the first write something like ...I would like to find solutions in C #


public partial class Form1 : Form
   {
       [DllImport("user32.dll")]
       static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);

       [DllImport("gdi32.dll")]
       static extern IntPtr CreateDC(string strDriver,
         string strDevice, string strOutput, IntPtr pData);

       [DllImport("user32.dll")]
       static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);

       [DllImport("gdi32.dll")]
       static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);

       [DllImport("gdi32.dll")]
       static extern bool DeleteDC(IntPtr hdc);

       static public System.Drawing.Color GetPixelColor(int x, int y)
       {
           IntPtr hdc = CreateDC("Display", null, null, IntPtr.Zero);
           uint pixel = GetPixel(hdc, x, y);
           ReleaseDC(IntPtr.Zero, hdc);
           Color color = Color.FromArgb((int)(pixel & 0x000000FF),
                        (int)(pixel & 0x0000FF00) >> 8,
                        (int)(pixel & 0x00FF0000) >> 16);
           DeleteDC(hdc);
           return color;
       }

       public Form1()
       {
           InitializeComponent();
           Visible = false;
       }

       private void Form1_Load(object sender, EventArgs e)
       {

       }
       [Flags]
       public enum MouseEventFlags
       {
           LEFTDOWN = 0x00000002,
           LEFTUP = 0x00000004,
           MIDDLEDOWN = 0x00000020,
           MIDDLEUP = 0x00000040,
           MOVE = 0x00000001,
           ABSOLUTE = 0x00008000,
           RIGHTDOWN = 0x00000008,
           RIGHTUP = 0x00000010
       }


       private void button1_Click(object sender, EventArgs e)
       {
           Bitmap  pix = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);

           this.Hide();
           Win32.POINT p = new Win32.POINT();
           int check = 0;
           while (check!=3)
           {
               for (int i = 0; i < 768; i += 3)
               {
                   for (int j = 0; j < 1366; j+=7)
                   {
                       Color color = GetPixelColor(p.x, p.y);
                       p.x = Convert.ToInt16(j);
                       p.y = Convert.ToInt16(i);
                       Win32.SetCursorPos(p.x, p.y);
                       if (Color.FromArgb(222, 11, 11) == color)
                       {
                           MessageBox.Show("1");
                           Thread.Sleep(3000);
                           Win32.ClientToScreen(Handle, ref p);

                           mouse_event((int)(MouseEventFlags.LEFTDOWN), p.x, p.y, 0, 0);
                           mouse_event((int)(MouseEventFlags.LEFTUP), p.x, p.y, 0, 0);

                       }
                   }
               }
               check++;
           }

推荐答案

这篇关于试图为C#中的在线游戏mmorpg编写机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆