源码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace llk_dt
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public byte[,] chessdata = new byte[11, 19];
[DllImport("User32")]
private static extern IntPtr FindWindow(string className, string windowName);
[DllImport("kernel32.dll ")]
static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[,] lpBuffer, int nSize, out int lpNumberOfBytesRead);
[DllImport("user32", EntryPoint = "GetWindowThreadProcessId")]
private static extern int GetWindowThreadProcessId(IntPtr hwnd,
out int lpdwProcessId);
[DllImport("kernel32.dll")]
public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
public void updata()
{
IntPtr fu1 = FindWindow("#32770", "QQ游?戏· - 连?连?看′角?色?版?");
const int PROCESS_VM_READ = 0x0010;
const int PROCESS_VM_WRITE = 0x0020;
if (fu1 != IntPtr.Zero)
{
int calcID;
int calcProcess;
int readByte;
GetWindowThreadProcessId(fu1, out calcID);
calcProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE, false, calcID);
ReadProcessMemory(calcProcess, 0x00189F78, chessdata, 11 * 19, out readByte);
}}
private void button1_Click(object sender, EventArgs e)
{
updata();
StringBuilder dayInfo = new StringBuilder();
for (int j = 0; j < 11; j++)
{
for (int i = 0; i < 19; i++)
{
if(i==18)
if (chessdata[j, i]<10)
dayInfo.Append("0"+chessdata[j, i].ToString() + "\r\n");
else
dayInfo.Append(chessdata[j, i].ToString() + "\r\n");
else
if (chessdata[j, i] < 10)
dayInfo.Append("0" + chessdata[j, i].ToString()+" ");
else
dayInfo.Append(chessdata[j, i].ToString()+" ");
}
}
MessageBox.Show(dayInfo.ToString());
}
public bool checkLine(Point a, Point b)//直±接ó相à连?
{
if (!(a.X == b.X || a.Y == b.Y))
return false;
int i;
bool match_x = false;
if (a.X == b.X)
{
match_x = true;
if (a.Y > b.Y)
for (i = a.Y - 1; i > b.Y; --i)
if (chessdata[i, a.X] != 0)
match_x = false;
if (b.Y> a.Y)
for (i = b.Y - 1; i > a.Y; --i)
if (chessdata[i, a.X] != 0)
match_x = false;
}
bool match_y = false;
if (a.Y == b.Y)
{
match_y = true;
if (a.X > b.X)
for (i = a.X - 1; i > b.X; --i)
if (chessdata[a.Y,i] != 0)
match_y = false;
if (b.X > a.X)
for (i = b.X - 1; i > a.X; --i)
if (chessdata[a.Y, i] != 0 )
match_y = false;
}
if (match_x || match_y)
{
return true;
}
return false;
}
public bool match_one_corner( Point a , Point b)
{
Point c=new Point(0,0);
Point d=new Point(0,0);
c.X = a.X;
c.Y = b.Y;
d.X = b.X;
d.Y = a.Y;
if (checkLine(c, a) && checkLine(c, b) && chessdata[c.Y, c.X] == 0)
return true;
if (checkLine(d, a) && checkLine(d, b)&&chessdata[d.Y, d.X] == 0)
return true;
return false;
}
public bool match_two_corner(Point a, Point b)
{
int i;
for( i=a.X -1 ; i>=0 ; --i )
if( chessdata[a.Y,i]!=0 )
break;
else
if (match_one_corner(new Point (i,a.Y), b))
{
return true ;
}
for( i = a.X +1 ; i<19 ; ++i )
if (chessdata[a.Y, i] != 0)
break;
else
if (match_one_corner(new Point(i, a.Y), b))
{
return true ;
}
for( i = a.Y - 1 ; i>=0 ; --i )
if (chessdata[i, a.X] != 0)
break;
else
if( match_one_corner( new Point(a.X, i), b ) )
{
return true ;
}
for( i = a.Y + 1 ; i<11 ; ++i )
if (chessdata[i, a.X] != 0)
break;
else
if(match_one_corner( new Point(a.X, i), b ))
{
return true ;
}
return false ;
}
public bool Check2p(Point a, Point b)
{
if (checkLine(a, b)||match_one_corner(a,b)||match_two_corner(a,b))
return true;
else
return false;
}
public void Click2p(Point p1,Point p2)
{
//点?击÷p1
const int WM_LBUTTONDOWN = 0x0201;
const int WM_LBUTTONUP = 0x0202;
IntPtr hwnd = FindWindow("#32770", "QQ游?戏· - 连?连?看′角?色?版?");
IntPtr lparam;
lparam = (IntPtr)((p1.Y * 35 + 198) << 16|(p1.X * 31 + 28));
SendMessage(hwnd, WM_LBUTTONDOWN, 0, lparam);//
SendMessage(hwnd, WM_LBUTTONUP, 0, lparam);//
//点?击÷p2
lparam = (IntPtr)((p2.Y * 35 + 198) << 16|(p2.X * 31 + 28));
SendMessage(hwnd, WM_LBUTTONDOWN, 0, lparam);//
SendMessage(hwnd, WM_LBUTTONUP, 0, lparam);//
}
public bool ClearPiar()
{
updata();
//遍括?历え?整?个?棋?盘ì 找ò出?相à同?类え?型í 一?对?棋?子哩?
Point p1 = new Point(0, 0);
Point p2 = new Point(0, 0);
int x1, y1, x2, y2;
for (y1 = 0; y1 < 11; y1++)
for (x1 = 0; x1 < 19; x1++)
{
for (y2 = 0; y2 < 11; y2++)
for (x2 = 0; x2 < 19; x2++)
if ((chessdata[y1, x1] == chessdata[y2, x2]) && (!((x1 == x2) && (y1 == y2))) && (chessdata[y1, x1] != 0) && (chessdata[y2, x2] != 0))
{
p1.X = x1; p1.Y = y1;
p2.X = x2; p2.Y = y2;
//检ì测a 相à同?的?2个?棋?子哩?是?否?可é消?y
if (Check2p(p1, p2))//如?果?可é消?除y 则ò返う?回?真?
{
//MessageBox.Show(p1.ToString() + " " + p2.ToString());
Click2p(p1, p2);
return true;
}
}
}
return false;
}
private void button2_Click(object sender, EventArgs e)
{
ClearPiar();
//if (ClearPiar())
//{
//MessageBox.Show("ture");
// }
//else
// MessageBox.Show("false");
}
private void button3_Click(object sender, EventArgs e)
{
Click2p(new Point(0, 0), new Point(0, 1));
}
private void button4_Click(object sender, EventArgs e)
{
for (int i = 0; i < 80;i++ )
ClearPiar();
}
}
}
理论上说度娘会吞掉这一楼