- UID
- 39467
注册时间2007-12-3
阅读权限10
最后登录1970-1-1
周游历练
TA的每日心情 | 慵懒 2020-9-27 20:02 |
---|
签到天数: 7 天 [LV.3]偶尔看看II
|
本帖最后由 爱民 于 2012-4-7 11:28 编辑
- unit GameFunction;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- //自动开始
- procedure AutoStart();
- //座位号
- function SeatNum():Integer;
- //根据座位返回地址
- Function SeatChessBase(SeatNum:DWORD):DWORD;
- //实现单消
- procedure ClearOnec();
- //优化速度
- procedure Accelerate();
- type
- TwoXY = array[1..2] of TPoint;
- QPArray = array[1..8,1..25] of Byte;
- var
- DDPChessData:QPArray;
- implementation
- Function SeatChessBase(SeatNum:DWORD):DWORD;
- begin
- Result:= 0;
- case SeatNum of 0..3:
- begin
- if SeatNum = 0 then
- begin
- Result:=$0048DA00;
- end;
- if SeatNum = 1 then
- begin
- Result:=$0048E5E4;
- end;
- if SeatNum = 2 then
- begin
- Result:=$0048F1C8;
- end;
- if SeatNum = 3 then
- begin
- Result:=$0048fDAC;
- end;
- end;
- end;
- end;
- function SeatNum():Integer;
- var
- hWnd:THandle;
- processh:THandle;
- dwProcessId:DWORD;
- bybyte:DWORD;
- Temp:DWORD;
- begin
- hWnd := FindWindow(nil,'对对碰角色版');
- GetWindowThreadProcessId(hWnd,@dwProcessid);
- processh := OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessid);
- ReadProcessMemory(processh,Pointer($00490FC0),@Temp,4,bybyte);
- Result:= Temp;
- end;
- //更新棋盘数据
- procedure UpDataChess();
- var
- Gameh:HWND;
- ProcessId:DWORD;
- GameProch:THandle;
- ReadByte:DWORD;
- begin
- Gameh:=FindWindow(nil,'对对碰角色版');
- GetWindowThreadProcessId(Gameh,@ProcessId);
- GameProch:=OpenProcess(PROCESS_ALL_ACCESS,False,ProcessId);
- ReadProcessMemory(GameProch,Pointer(SeatChessBase(SeatNum())),@DDPChessData,200,ReadByte);
- end;
- //测试交换过的棋盘 内是否有 三个相同棋子相连 3
- Function TestChess(ChessDataTemp:QPArray):BOOL;
- var
- r1,x,y:byte;
- begin
- Result:=false;
- for y:=1 to 8 do //1-8行坐标
- begin
- r1:=1;
- for x:=1 to 8 do //Y列坐标
- begin
- if ChessDataTemp[x][y]=ChessDataTemp[x+1][y] then
- begin
- r1:=r1+1 ; //累计相同棋子数
- if r1>=3 then
- begin
- Result:=true;
- exit;
- end;
- end
- else
- r1:=1; //初始化累计 1
- end;
- end;
- /////////////////////////////////////////////////////////////////////////////////////////
- //遍历 1-8 列 看是否有 3子 相连的
- for x:=1 to 8 do //
- begin
- r1:=1;
- for y:=1 to 8 do //列坐标
- begin
- if ChessDataTemp[x][y]=ChessDataTemp[x][y+1] then
- begin r1:=r1+1 ; //累计 相同的棋子数
- if r1>=3 then
- begin
- Result:=true;
- exit;
- end;
- end
- else
- r1:=1; //如果相临棋子 不同,则初如化累计值
- end;
- end;
- end; //end function
- //获得交换点
- function GetPoint():TwoXY;
- var
- x,y,t1:Byte;
- ChessDataTemp:QPArray;
- begin
- for x:=1 to 8 do //1-8列
- for y:=1 to 7 do // 遍历某列
- begin
- UpdataChess(); //更新棋盘数据
- ChessDataTemp:= DDPChessData;
- t1:=ChessDataTemp[x][y]; ChessDataTemp[x][y]:=ChessDataTemp[x][y+1]; ChessDataTemp[x][y+1]:=t1; //交换相临棋子
- if TestChess(ChessDataTemp) then
- begin
- result[1].X:=x;
- result[1].Y:=y;
- result[2].X:=x;
- result[2].Y:=y+1;
- exit;
- end;
- end;
- for y:=1 to 8 do
- for x:=1 to 7 do
- begin
- updataChess; //更新棋盘数据
- ChessDataTemp :=DDPChessData; //
- t1:=ChessDataTemp[x][y]; ChessDataTemp[x][y]:=ChessDataTemp[x+1][y]; ChessDataTemp[x+1][y]:=t1; //交换相临的2点
- if TestChess(ChessDataTemp) then
- begin //如果交换后的棋盘 存在 三个相同的棋子相连
- result[1].X:=x;
- result[1].Y:=y;
- result[2].X:=x+1;
- result[2].Y:=y;
- exit;
- end;
- end;//end for
- end;
- //自动交换棋子
- procedure AutoPlay(Pa:TPoint; Pb:TPoint);
- var
- Gameh:HWND;
- P1,P2:TPoint;
- lParam:DWORD;
- begin
- Gameh:=FindWindow(nil,'对对碰角色版');
- P1.X:=292+Pa.X*48-48; P1.Y:=118+Pa.Y*48-48;
- P2.X:=292+Pb.X*48-48; P2.Y:=118+Pb.Y*48-48;
- lParam:=(P1.Y shl 16)+P1.X;
- SendMessage(Gameh,messages.WM_LBUTTONDOWN,0,lParam);
- SendMessage(Gameh,messages.WM_LBUTTONUP,0,lParam);
- lParam:=(P2.Y shl 16)+P2.X;
- SendMessage(Gameh,messages.WM_LBUTTONDOWN,0,lParam);
- SendMessage(Gameh,messages.WM_LBUTTONUP,0,lParam);
- end;
- //实现单消
- procedure ClearOnec();
- var
- ChessXY:TwoXY;
- begin
- ChessXY:=GetPoint();
- AutoPlay(ChessXY[1],ChessXY[2]);
- end;
- //自动开始
- procedure AutoStart();
- var
- hWnd:THandle;
- r1:TRect;
- p:TPoint;
- begin
- hWnd := FindWindow(nil,'对对碰角色版');
- SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW);
- GetWindowRect(hWnd,r1);
- GetCursorPos(p);
- SetCursorPos(395+r1.left,395+r1.top);
- mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
- mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
- mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
- Sleep(200);
- SetCursorPos(p.x,p.y);
- end;
- //优化速度
- procedure Accelerate();
- Var
- hWnd:THandle;
- processh:THandle;
- dwProcessId:DWORD;
- dwOldProtect:DWORD;
- bybyte:DWORD;
- Temp:Array [1..2] of Byte;
- begin
- hWnd := FindWindow(nil,'对对碰角色版');
- GetWindowThreadProcessId(hWnd,@dwProcessid);
- processh := OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessid);
- VirtualProtect(Pointer($004208CD), 4,PAGE_EXECUTE_READWRITE, &dwOldProtect);
- Temp[1] := $90;
- Temp[2] := $90;
- WriteProcessMemory(processh,Pointer($004208CD),@Temp[1],2,bybyte);
- VirtualProtect(Pointer($004208CD), 4,dwOldProtect, &dwOldProtect);
- end;
- end.
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入我们
x
|