C# QQ连连看外挂(内存版)源代码

小学码农 2012-02-08 11:26:42
加精
发一个C#QQ连连看外挂(内存版)源代码
现在游戏的基址已经改变了大家只要重新查找一下基址就直接可以用了
里面用了最经典的寻路算法(比递归算法快100倍+)
Main.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


namespace llk_wg {

class Main {
//游戏窗口标题
const string GAME_CAPTION = "QQ游戏 - 连连看角色版";
//棋盘基址
static IntPtr GAME_BASE = (IntPtr)0x0012A47C;
//声明一个棋盘数组
static byte[,] boxs = new byte[11, 19];
//游戏窗口句柄
static IntPtr hwnd;
//初始化棋盘数组
static void InitBox() {
//获取游戏句柄
hwnd = Win32.FindWindow(null, GAME_CAPTION);
//获取棋盘数组的内存基址
IntPtr lpBufferbase = Marshal.UnsafeAddrOfPinnedArrayElement(boxs, 0);
//获取pid
int ProcessId;
Win32.GetWindowThreadProcessId(hwnd, out ProcessId);
//打开游戏线程
IntPtr hObject = Win32.OpenProcess(Win32.STANDARD_RIGHTS_REQUIRED | Win32.SYNCHRONIZE | 4095, false, ProcessId);
//读取棋盘数据
Win32.ReadProcessMemory(hObject, GAME_BASE, lpBufferbase, boxs.Length, IntPtr.Zero);
//关闭线程
Win32.CloseHandle(hObject);
}
//发送鼠标消息(顺便把图片的高度宽度也算进去)
static void SendMouseclick(int x, int y) {
//获取游戏句柄
hwnd = Win32.FindWindow(null, GAME_CAPTION);
//lparam的高位就是y坐标低位就是x坐标y左移16就到高位去了
int lparam = (y << 16) + x;
Win32.PostMessage(hwnd, Win32.WM_LBUTTONDOWN, 0, lparam);
Win32.PostMessage(hwnd, Win32.WM_LBUTTONUP, 0, lparam);
}
//消除1对图片(模拟2次鼠标单击)
static void ClickTwo(int x1, int y1, int x2, int y2) {
SendMouseclick(22 + x1 * 31, 194 + y1 * 35);
SendMouseclick(22 + x2 * 31, 194 + y2 * 35);
}
//游戏开局
public static void Start(int type) {
int x = type == 1 ? 660 : 760;
SendMouseclick(x, 570);
}
//找相同的图片(本工具的核心)
static bool Select(int x1, int y1, int x2, int y2) {

if (x1 == x2 && y1 + 1 == y2) return true;
if (y1 == y2 && x1 + 1 == x2) return true;

List<int> list1 = new List<int>();
List<int> list2 = new List<int>();
List<int> list3 = new List<int>();

bool flag;

list1.Add(x1);
for (int i = x1 - 1; i >= 0; i--) if (boxs[i, y1] == 0) list1.Add(i); else break;
for (int i = x1 + 1; i < 11; i++) if (boxs[i, y1] == 0) list1.Add(i); else break;

list2.Add(x2);
for (int i = x2 - 1; i >= 0; i--) if (boxs[i, y2] == 0) list2.Add(i); else break;
for (int i = x2 + 1; i < 11; i++) if (boxs[i, y2] == 0) list2.Add(i); else break;

list3 = list1.Intersect(list2).ToList();

for (int i = 0; i < list3.Count(); i++) {
flag = true;
for (int j = Math.Min(y1, y2) + 1; j < Math.Max(y1, y2); j++) { if (boxs[list3[i], j] != 0) { flag = false; break; } }
if (flag) return true;
}

list1.Clear(); list2.Clear(); list3.Clear();

list1.Add(y1);
for (int i = y1 - 1; i >= 0; i--) if (boxs[x1, i] == 0) list1.Add(i); else break;
for (int i = y1 + 1; i < 19; i++) if (boxs[x1, i] == 0) list1.Add(i); else break;

list2.Add(y2);
for (int i = y2 - 1; i >= 0; i--) if (boxs[x2, i] == 0) list2.Add(i); else break;
for (int i = y2 + 1; i < 19; i++) if (boxs[x2, i] == 0) list2.Add(i); else break;

list3 = list1.Intersect(list2).ToList();

for (int i = 0; i < list3.Count(); i++) {
flag = true;
for (int j = Math.Min(x1, x2) + 1; j < Math.Max(x1, x2); j++) { if (boxs[j, list3[i]] != 0) { flag = false; break; } }
if (flag) return true;
}

return false;
}
//消除一对
public static void RemoveSingle() {
InitBox();

for (int x1 = 0; x1 < 11; x1++) {
for (int y1 = 0; y1 < 19; y1++) {
for (int x2 = 0; x2 < 11; x2++) {
for (int y2 = 0; y2 < 19; y2++) {
if (boxs[x1, y1] != 0 && boxs[x1, y1] == boxs[x2, y2] && !(x1 == x2 && y1 == y2)) {
if (Select(x1, y1, x2, y2)) {
ClickTwo(y1, x1, y2, x2);
return;
}
}
}
}
}
}
}
//消除所有
public static void RemoveAll() {
InitBox();
Target:
for (int x1 = 0; x1 < 11; x1++) {
for (int y1 = 0; y1 < 19; y1++) {
for (int x2 = 0; x2 < 11; x2++) {
for (int y2 = 0; y2 < 19; y2++) {
if (boxs[x1, y1] != 0 && boxs[x1, y1] == boxs[x2, y2] && !(x1 == x2 && y1 == y2)) {
if (Select(x1, y1, x2, y2)) {
ClickTwo(y1, x1, y2, x2);
boxs[x1, y1] = 0;
boxs[x2, y2] = 0;
goto Target;
}
}
}
}
}
}
}
//获取其他玩家最小box数量值
public static byte GetOtherUserMinNum() {
byte value = 0;
byte[] buffer = new byte[20];
int lpBase = 0x0012E04C;// 0x00115CDC;//0012E04C
//获取游戏句柄
hwnd = Win32.FindWindow(null, GAME_CAPTION);
//获取棋盘数组的内存基址
IntPtr lpBufferbase = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
//获取pid
int ProcessId;
Win32.GetWindowThreadProcessId(hwnd, out ProcessId);
//打开游戏线程
IntPtr hObject = Win32.OpenProcess(Win32.STANDARD_RIGHTS_REQUIRED | Win32.SYNCHRONIZE | 4095, false, ProcessId);
//读取棋盘数据
Win32.ReadProcessMemory(hObject, (IntPtr)lpBase, lpBufferbase, buffer.Length, IntPtr.Zero);
//关闭线程
Win32.CloseHandle(hObject);
try { value = buffer.Where(o => o != 0).Min(); } catch { }
return value;
}
//获取自己的图片数量
public static byte GetShengyuNum() {
byte[] buffer = new byte[4];
//0012E048,00115CD8
int lpBase = 0x0012E048;// 0x00115CDC;//0012E04C
//获取游戏句柄
hwnd = Win32.FindWindow(null, GAME_CAPTION);
//获取棋盘数组的内存基址
IntPtr lpBufferbase = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0);
//获取pid
int ProcessId;
Win32.GetWindowThreadProcessId(hwnd, out ProcessId);
//打开游戏线程
IntPtr hObject = Win32.OpenProcess(Win32.STANDARD_RIGHTS_REQUIRED | Win32.SYNCHRONIZE | 4095, false, ProcessId);
//读取棋盘数据
Win32.ReadProcessMemory(hObject, (IntPtr)lpBase, lpBufferbase, buffer.Length, IntPtr.Zero);
//关闭线程
Win32.CloseHandle(hObject);
return Marshal.ReadByte(lpBufferbase);
}
}
}
...全文
10731 181 打赏 收藏 转发到动态 举报
写回复
用AI写文章
181 条回复
切换为时间正序
请发表友善的回复…
发表回复
fuermoshia 2012-04-27
  • 打赏
  • 举报
回复
[Quote=引用 54 楼 的回复:]
我是搞java的 ,看到这个算法 不禁使我想起一些往事,每当有人说他是搞C的时候,我总要情不自禁的去看看他的头发。
[/Quote]



不至于吧!这跟你自己的一些习惯也有关系啊,好好保养还是可以的
H_1991_Y 2012-04-24
  • 打赏
  • 举报
回复
顶 楼主给力!~!~!~1
wzuomin 2012-04-17
  • 打赏
  • 举报
回复
写外挂的都很牛啊,呵呵。。。
autumnsky_pet 2012-04-16
  • 打赏
  • 举报
回复
//棋盘基址
static IntPtr GAME_BASE = (IntPtr)0x0012A47C;
是不是可以用
public static extern IntPtr WindowFromPoint(int xPoint, int yPoint);
不知道获取的是不是一样的东西
zhong_wenjun 2012-03-29
  • 打赏
  • 举报
回复
如何获取进程的基地址?我在写斗地主的记牌器,为了适应版本变化,得在程序中获取进程的基地址才行。
fanfanrot 2012-03-06
  • 打赏
  • 举报
回复
学习下算法
。。。。
茄果 2012-03-06
  • 打赏
  • 举报
回复
楼主顺便普及一下找基址的方法吧
ych2020 2012-03-06
  • 打赏
  • 举报
回复
学习了。。。感谢楼主
polk6 2012-03-06
  • 打赏
  • 举报
回复
先收藏,以后再研究研究
littleasp3 2012-03-06
  • 打赏
  • 举报
回复
什么叫基址呀?
喜阳阳 2012-03-06
  • 打赏
  • 举报
回复
NewUser2008 2012-03-06
  • 打赏
  • 举报
回复
留名,下班了在看!
mada1989520 2012-03-06
  • 打赏
  • 举报
回复
C#写的代码,支持下
falcon_fei 2012-03-06
  • 打赏
  • 举报
回复
这个算法是个什么原理呀。
popkart0727 2012-03-05
  • 打赏
  • 举报
回复
有点意思
jueying3 2012-02-22
  • 打赏
  • 举报
回复
rencai ^^JjjJJ
shiyimjjcn 2012-02-22
  • 打赏
  • 举报
回复
这个东西都有!!!
loki006 2012-02-22
  • 打赏
  • 举报
回复
高手 借鉴一下
wangtiantian23 2012-02-22
  • 打赏
  • 举报
回复
太好了!!楼主很强大!
PaulyJiang 2012-02-22
  • 打赏
  • 举报
回复
点个灯 晚上回去看
加载更多回复(161)
是win7 x64的主要算法代码如下: public class robot { public robot(byte[] robotbyte,int x,int y) { this.robotbyte = new byte[x,y]; for (int j = 0; j < y; j++) { for (int i = 0; i < x; i++) { this.robotbyte[i, j] = robotbyte[j * x + i]; } } this.backupbyte = new byte[x, y]; this.backupbyte = this.robotbyte; this.robotheight = y; this.robotwidth = x; this.steps = new List(); this.firstpoint = new Point(0, 0); this.secondpoint = new Point(1,0); } public byte[,] robotbyte; public byte[,] backupbyte; public int robotwidth; public int robotheight; public int unitcount; public int bushu; private Point firstpoint; private Point secondpoint; public List steps; private bool dealroundpoint(Point firstp,out Point secondp) { bool isconnect = false; if (robotbyte[firstp.X, firstp.Y] == GetValueByPos(new Point(firstp.X,firstp.Y-1))) { secondp = new Point(firstp.X, firstp.Y - 1); isconnect = true; } else { if (robotbyte[firstp.X, firstp.Y] ==GetValueByPos(new Point(firstp.X+1,firstp.Y))) { secondp = new Point(firstp.X + 1, firstp.Y); isconnect = true; } else { if (robotbyte[firstp.X, firstp.Y] == GetValueByPos(new Point(firstp.X-1,firstp.Y))) { secondp = new Point(firstp.X - 1, firstp.Y); isconnect=true; } else { if (robotbyte[firstp.X, firstp.Y] == GetValueByPos(new Point(firstp.X,firstp.Y+1))) { secondp = new Point(firstp.X, firstp.Y + 1); isconnect = true; } else { secondp = firstp; } } } } return isconnect; } private bool shulinepoint(Point firstp, Point secondp,Point range) { bool isconnect=false; if (firstp.Y > secondp.Y) { Point tempp = firstp; firstp = secondp; secondp = firstp; } for (int i=range.X; i <=range.Y; i++) { for (int j=firstp.Y+1; j secondp.X) { Point tempp = firstp; firstp = secondp; secondp = firstp; } for (int i =range.X; i <=range.Y; i++) { for (int j = firstp.X+1; j sp.Y) { if (fp.X <= sp.Y) { isjiao = true; } } else if (fp.Y == sp.Y) { isjiao = true; } else { if (fp.Y >= sp.X) { isjiao = true; } } if (isjiao) { range.X = Math.Max(fp.X, sp.X); range.Y = Math.Min(fp.Y, sp.Y); } return isjiao; } private Point GetXRange(Point tempp) { int min=tempp.X; int max=tempp.X; while (min >0) { min--; if (robotbyte[min, tempp.Y] != 0) { min = min + 1; break; } } while (max < this.robotheight-1) { max++; if (robotbyte[max,tempp.Y] != 0) { max = max - 1; break; } } return new Point(min, max); } private Point GetYRange(Point tempp) { int min = tempp.Y; int max = tempp.Y; while (min>0) { min--; if (robotbyte[tempp.X, min]!=0) { min = min + 1; break; } } while(max 0) { fp = new Point(fj, fi); if (dealroundpoint(fp, out sp)) { steps.Add(new Step(fp, sp)); robotbyte[fp.X, fp.Y] = 0; robotbyte[sp.X, sp.Y] = 0; stepmark++; } } } } while (stepmark< this.bushu) { int tempstepmark = stepmark; for (int fi = 0; fi < robotheight; fi++) { for (int fj = 0; fj < robotwidth; fj++) { if (this.GetValueByPos(new Point(fj, fi)) > 0) { fp = new Point(fj, fi); if(this.dealroundpointE(fp,out sp)) { steps.Add(new Step(fp, sp)); robotbyte[fp.X, fp.Y] = 0; robotbyte[sp.X, sp.Y] = 0; stepmark++; continue; } List sps = GetSecondByOnePos(fp); foreach (var temp in sps) { if (dealtwopoint(fp, temp)) { steps.Add(new Step(fp, temp)); robotbyte[fp.X, fp.Y] = 0; robotbyte[temp.X, temp.Y] = 0; stepmark++; break; } } } } } if (tempstepmark == stepmark) { break; } } } private List GetSecondByOnePos(Point fp) { List sp = new List(); for (int sj = 0; sj < robotheight; sj++) { for (int si = 0; si < robotwidth; si++) { if (this.robotbyte[fp.X, fp.Y] == this.robotbyte[si, sj]) { if (fp.X != si||fp.Y != sj) { sp.Add(new Point(si,sj )); } } } } return sp; } public class Step { public Point fp; public Point sp; public Step(Point fp,Point sp) { this.fp = fp; this.sp = sp; } } }

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧