博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用纯C语言写的一个植物大战僵尸的外挂
阅读量:5227 次
发布时间:2019-06-14

本文共 15356 字,大约阅读时间需要 51 分钟。

转载请注明来源:

这个外挂主要用来帮助鼠标点击的。最近很忙,代码注释我以后会慢慢补充进来。请多多指点。

1 #include "PC2StdAfx.h"  2   3 BOOL CALLBACK PCEnumDlgItem(HWND,LPARAM);  4 BOOL CALLBACK PCEnumWindows(HWND,LPARAM);  5 LRESULT CALLBACK PCMainWinProc(HWND,UINT,WPARAM,LPARAM);  6 BOOL CALLBACK PCHelpWinProc(HWND,UINT,WPARAM,LPARAM);  7 void PC2WmHotKey(HWND hwnd,WPARAM wparam);  8 void PC2WmCommand(HWND hwnd,WPARAM wparam);  9 void PC2WmTimer(); 10  11 TCHAR szAppName[]=TEXT("PCMainWin"); 12  13 //界面类 14 TCHAR szStart[256],szStop[256],szPointFormat[256],szHelpResName[256],szComputePoint[256],szClearPoint[256]; 15 //提示类 16 TCHAR szMousePositionError[256],szOperateTip[256],szGlobalFastKey[256],szLUFirst[256],szLUBiggerRD[256],szPointNotComeplete[256]; 17  18 static HFONT hfont; 19 HWND hDlg=NULL; 20  21 int WINAPI WinMain( IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd ) 22 { 23     MSG msg; 24     HWND hwnd; 25     WNDCLASS wc; 26      27     TCHAR szFontName[256]; 28     wc.cbClsExtra=0; 29     wc.cbWndExtra=DLGWINDOWEXTRA; 30     wc.hbrBackground=CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); 31     wc.hCursor=LoadCursor(hInstance,TEXT("PCCursor")); 32     wc.hIcon=LoadIcon(hInstance,TEXT("PCIcon")); 33     wc.hInstance=hInstance; 34     wc.lpfnWndProc=PCMainWinProc; 35     wc.lpszClassName=szAppName; 36     wc.lpszMenuName=TEXT("PCMenu"); 37     wc.style=CS_HREDRAW|CS_VREDRAW; 38     if (!RegisterClass(&wc)) 39     { 40         return 0; 41     } 42     hwnd=CreateDialog(hInstance,szAppName,NULL,NULL); 43     if (!hwnd) 44     { 45         return 0; 46     } 47     LoadString(hInstance,IDS_STRINGFONT,szFontName,256); 48     LoadString(hInstance,IDS_MOUSEPOSITIONERROR,szMousePositionError,256); 49     LoadString(hInstance,IDS_OPERATETIP,szOperateTip,256); 50     LoadString(hInstance,IDS_START,szStart,256); 51     LoadString(hInstance,IDS_STOP,szStop,256); 52     LoadString(hInstance,IDS_POINTFORMAT,szPointFormat,256); 53     LoadString(hInstance,IDS_GLOBALFASTKEY,szGlobalFastKey,256); 54     LoadString(hInstance,IDS_HELPRESNAME,szHelpResName,256); 55     LoadString(hInstance,IDS_COMPUTEPOINT,szComputePoint,256); 56     LoadString(hInstance,IDS_CLEARPOINT,szClearPoint,256); 57     LoadString(hInstance,IDS_LUFIRST,szLUFirst,256); 58     LoadString(hInstance,IDS_LUBIGGERRD,szLUBiggerRD,256); 59     LoadString(hInstance,IDS_POINTNOTCOMPLETE,szPointNotComeplete,256); 60     hfont=CreateFont(18,0,0,0,FW_NORMAL,NULL,NULL,NULL,GB2312_CHARSET,NULL,NULL,NULL,NULL,szFontName); 61     if (hfont==NULL) 62     { 63         hfont=(HFONT)GetStockObject(DEFAULT_GUI_FONT); 64     } 65     SendMessage(hwnd,0xFFFC,NULL,(LPARAM)hfont); 66     while (GetMessage(&msg,NULL,0,0)) 67     { 68         if (hDlg==0||!IsDialogMessage(hDlg,&msg)) 69         { 70             TranslateMessage(&msg); 71             DispatchMessage(&msg); 72         } 73     } 74     return 0; 75 } 76  77 //主窗口消息处理函数。 78 LRESULT CALLBACK PCMainWinProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)  79 { 80     switch (msg) 81     { 82     case 0xFFFC: 83         EnumWindows((WNDENUMPROC)PCEnumWindows,NULL); 84         EnumChildWindows(hwnd,(WNDENUMPROC)PCEnumDlgItem,lparam); 85         InvalidateRect(hwnd,NULL,true); 86         //CTRL+SHIFT+A 87         RegisterHotKey(hwnd,PICKCOIN_LU,MOD_CONTROL|MOD_SHIFT,0x41); 88         //CTRL+SHIFT+S 89         RegisterHotKey(hwnd,PICKCOIN_START,MOD_CONTROL|MOD_SHIFT,0x53); 90         //CTRL+SHIFT+Z 91         RegisterHotKey(hwnd,PICKCOIN_COMPUTE,MOD_CONTROL|MOD_SHIFT,0x5A); 92         //CTRL+SHIFT+X 93         RegisterHotKey(hwnd,PICKCOIN_RD,MOD_CONTROL|MOD_SHIFT,0x58); 94         return 0; 95     case WM_HOTKEY: 96         PC2WmHotKey(hwnd,wparam); 97         return 0; 98     case WM_KEYDOWN: 99         switch(wparam)100         {101         case VK_SHIFT:102             break;103         }104         return 0;105     case WM_TIMER:106         PC2WmTimer();107         return 0;108     case WM_COMMAND:109         PC2WmCommand(hwnd,wparam);110         return 0;111     case WM_DESTROY:112         UnregisterHotKey(hwnd,PICKCOIN_LU);113         UnregisterHotKey(hwnd,PICKCOIN_RD);114         UnregisterHotKey(hwnd,PICKCOIN_START);115         UnregisterHotKey(hwnd,PICKCOIN_COMPUTE);116         PostQuitMessage(0);117         return 0;118     }119     return DefWindowProc(hwnd,msg,wparam,lparam);120 }121 122 //设定控件字体。123 BOOL CALLBACK PCEnumDlgItem(HWND hwnd,LPARAM lparam)124 {125     SendMessage(hwnd,WM_SETFONT,(WPARAM)(HFONT)lparam,NULL);126     return true;127 }128 129 130 131 //帮助对话框,返回值0表示需要windows自带消息处理函数处理逻辑。132 BOOL CALLBACK PCHelpWinProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)133 {134     switch(msg)135     {136     case WM_INITDIALOG:137         EnumChildWindows(hwnd,(WNDENUMPROC)PCEnumDlgItem,(LPARAM)hfont);138         return 0;139     case WM_NCLBUTTONDOWN:140         if (DefWindowProc(hwnd,WM_NCHITTEST,wparam,lparam)==HTCLOSE)141         {142             EndDialog(hwnd,TRUE);143             hDlg=NULL;144             return 0;145         }146         return false;147     case WM_DESTROY:148         EndDialog(hwnd,TRUE);149         return 0;150     }151     return 0;152 }
#define _WIN32_WINNT 0x0601#define WINVER 0x0601#define PICKCOIN_LU 0x7FFC#define PICKCOIN_RD 0x7FFB#define PICKCOIN_COMPUTE 0x7FFA#define PICKCOIN_START 0x7FF9#define ID_PICKCOIN_TIMER 0x7FF8#define PICKCOIN_PIXELDISTANCE 40#define PICKCOIN_TIMESPAN 1000#include 
#include
#include "resource.h"#ifdef _WIN32_WINNT#endif
1 //{
{NO_DEPENDENCIES}} 2 // Microsoft Developer Studio generated include file. 3 // Used by PC2Res.rc 4 // 5 #define IDS_STRING1 1 6 #define IDS_STRINGFONT 1 7 #define IDS_MOUSEPOSITIONERROR 2 8 #define IDS_OPERATETIP 3 9 #define IDS_START 410 #define IDS_STOP 511 #define IDS_POINTFORMAT 612 #define IDS_GLOBALFASTKEY 713 #define IDS_HELPRESNAME 814 #define IDS_COMPUTEPOINT 915 #define IDS_CLEARPOINT 1016 #define IDS_LUFIRST 1117 #define IDS_LUBIGGERRD 1218 #define IDS_POINTNOTCOMPLETE 1319 #define IDC_BUTTONLU 100020 #define IDC_BUTTONSTART 100121 #define IDC_STATICLU 100222 #define IDC_BUTTONRD 100723 #define IDC_STATICRD 100824 #define IDC_BUTTONCOMPUTE 100925 #define ID_MENUITEM40001 4000126 27 // Next default values for new objects28 // 29 #ifdef APSTUDIO_INVOKED30 #ifndef APSTUDIO_READONLY_SYMBOLS31 #define _APS_NEXT_RESOURCE_VALUE 10632 #define _APS_NEXT_COMMAND_VALUE 4000233 #define _APS_NEXT_CONTROL_VALUE 101534 #define _APS_NEXT_SYMED_VALUE 10135 #endif36 #endif
1 //Microsoft Developer Studio generated resource script.  2 //  3 #include "resource.h"  4   5 #define APSTUDIO_READONLY_SYMBOLS  6 /////  7 //  8 // Generated from the TEXTINCLUDE 2 resource.  9 // 10 #include "afxres.h" 11  12 ///// 13 #undef APSTUDIO_READONLY_SYMBOLS 14  15 ///// 16 // Chinese (P.R.C.) resources 17  18 #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) 19 #ifdef _WIN32 20 LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED 21 #pragma code_page(936) 22 #endif //_WIN32 23  24 #ifdef APSTUDIO_INVOKED 25 ///// 26 // 27 // TEXTINCLUDE 28 // 29  30 1 TEXTINCLUDE DISCARDABLE  31 BEGIN 32     "resource.h\0" 33 END 34  35 2 TEXTINCLUDE DISCARDABLE  36 BEGIN 37     "#include ""afxres.h""\r\n" 38     "\0" 39 END 40  41 3 TEXTINCLUDE DISCARDABLE  42 BEGIN 43     "\r\n" 44     "\0" 45 END 46  47 #endif    // APSTUDIO_INVOKED 48  49  50 ///// 51 // 52 // Dialog 53 // 54  55 PCMAINWIN DIALOG DISCARDABLE  0, 0, 187, 122 56 STYLE DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 57 CAPTION "植物大战僵尸鼠标外挂——zhuangtaiqiusi@163.com" 58 CLASS "PCMainWin" 59 FONT 10, "System" 60 BEGIN 61     PUSHBUTTON      "定位(CTRL+SHIFT+A)",IDC_BUTTONLU,13,13,86,18 62     RTEXT           "左上角:",IDC_STATIC,100,13,33,18,SS_CENTERIMAGE 63     LTEXT           "(0,0)",IDC_STATICLU,136,13,44,18,SS_CENTERIMAGE 64     PUSHBUTTON      "开始(CTRL+SHIFT+S)",IDC_BUTTONSTART,13,85,160,18 65     PUSHBUTTON      "定位(CTRL+SHIFT+X)",IDC_BUTTONRD,13,37,86,18 66     RTEXT           "右下角:",IDC_STATIC,100,38,33,18,SS_CENTERIMAGE 67     LTEXT           "(0,0)",IDC_STATICRD,136,38,44,18,SS_CENTERIMAGE 68     PUSHBUTTON      "计算坐标(CTRL_SHIFT+Z)",IDC_BUTTONCOMPUTE,13,61,160,18 69 END 70  71 PCHELP DIALOG DISCARDABLE  0, 0, 187, 94 72 STYLE DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 73 CAPTION "关于作者" 74 FONT 10, "System" 75 BEGIN 76     LTEXT           "作者:曹威",IDC_STATIC,7,7,173,14 77     LTEXT           "联系方式:zhuangtaiqiusi@163.com",IDC_STATIC,7,23,173, 78                     14 79     LTEXT           "版权所有,侵权必究",IDC_STATIC,7,39,173,14 80     LTEXT           "^_^ ^_^",IDC_STATIC,7,55,173,14 81 END 82  83  84 ///// 85 // 86 // DESIGNINFO 87 // 88  89 #ifdef APSTUDIO_INVOKED 90 GUIDELINES DESIGNINFO DISCARDABLE  91 BEGIN 92     "PCMAINWIN", DIALOG 93     BEGIN 94         LEFTMARGIN, 7 95         RIGHTMARGIN, 180 96         TOPMARGIN, 7 97         BOTTOMMARGIN, 115 98     END 99 100     "PCHELP", DIALOG101     BEGIN102         LEFTMARGIN, 7103         RIGHTMARGIN, 180104         TOPMARGIN, 7105         BOTTOMMARGIN, 87106     END107 END108 #endif    // APSTUDIO_INVOKED109 110 111 /////112 //113 // Icon114 //115 116 // Icon with lowest ID value placed first to ensure application icon117 // remains consistent on all systems.118 PCICON                  ICON    DISCARDABLE     "FACE02.ICO"119 120 /////121 //122 // Cursor123 //124 125 PCCURSOR                CURSOR  DISCARDABLE     "cursor1.cur"126 127 /////128 //129 // Menu130 //131 132 PCMENU MENU DISCARDABLE 133 BEGIN134     POPUP "帮助"135     BEGIN136         MENUITEM "关于作者",                    ID_MENUITEM40001137     END138 END139 140 141 /////142 //143 // String Table144 //145 146 STRINGTABLE DISCARDABLE 147 BEGIN148     IDS_STRINGFONT          "华文中宋"149     IDS_MOUSEPOSITIONERROR  "鼠标请放置于目标窗口的显示范围内!"150     IDS_OPERATETIP          "操作提示"151     IDS_START               "开始(CTRL+SHIFT+S)"152     IDS_STOP                "停止(CTRL+SHIFT+S)"153     IDS_POINTFORMAT         "(%d,%d)"154     IDS_GLOBALFASTKEY       "请使用全局快捷键!"155     IDS_HELPRESNAME         "PCHelp"156     IDS_COMPUTEPOINT        "计算坐标(CTRL_SHIFT+Z)"157     IDS_CLEARPOINT          "清空坐标(CTRL_SHIFT+Z)"158     IDS_LUFIRST             "请先定义左上角坐标!"159     IDS_LUBIGGERRD          "左上角坐标大于右下角坐标!"160     IDS_POINTNOTCOMPLETE    "坐标未定义完毕。请检查左上角坐标和右下角坐标的值。"161 END162 163 #endif    // Chinese (P.R.C.) resources164 /////165 166 167 168 #ifndef APSTUDIO_INVOKED169 /////170 //171 // Generated from the TEXTINCLUDE 3 resource.172 //173 174 175 /////176 #endif    // not APSTUDIO_INVOKED

 

1 #include "PC2StdAfx.h"  2   3 extern HWND hDlg;  4 //界面类  5 extern TCHAR szStart[256],szStop[256],szPointFormat[256],szHelpResName[256],szComputePoint[256],szClearPoint[256];  6 //提示类  7 extern TCHAR szMousePositionError[256],szOperateTip[256],szGlobalFastKey[256],szLUFirst[256],szLUBiggerRD[256],szPointNotComeplete[256];  8   9 bool bBeg=false,bCompute=false; 10 std::vector
vpt; 11 HWND hDst=NULL; 12 RECT rtDst; 13 14 void PC2ButtonStart(HWND hwnd); 15 void PC2ComputePoint(HWND hwnd); 16 BOOL CALLBACK PCHelpWinProc(HWND,UINT,WPARAM,LPARAM); 17 18 void PC2WmHotKey(HWND hwnd,WPARAM wparam) 19 { 20 TCHAR szLocation[256]; 21 POINT pt; 22 switch(wparam) 23 { 24 case PICKCOIN_LU: 25 GetCursorPos(&pt); 26 ScreenToClient(hDst,&pt); 27 if (pt.x<0||pt.x>rtDst.right-rtDst.left||pt.y<0||pt.y>rtDst.bottom-rtDst.top) 28 { 29 MessageBox(hwnd,szMousePositionError,szOperateTip,MB_OK|MB_ICONERROR); 30 break; 31 } 32 vpt.clear(); 33 vpt.push_back(pt); 34 wsprintf(szLocation,szPointFormat,pt.x,pt.y); 35 SetDlgItemText(hwnd,IDC_STATICLU,szLocation); 36 break; 37 case PICKCOIN_RD: 38 if (vpt.size()==0) 39 { 40 MessageBox(hwnd,szLUFirst,szOperateTip,MB_OK|MB_ICONERROR); 41 break; 42 } 43 GetCursorPos(&pt); 44 ScreenToClient(hDst,&pt); 45 if (pt.x<0||pt.x>rtDst.right-rtDst.left||pt.y<0||pt.y>rtDst.bottom-rtDst.top) 46 { 47 MessageBox(hwnd,szMousePositionError,szOperateTip,MB_OK|MB_ICONERROR); 48 break; 49 } 50 while (vpt.size()>1) 51 { 52 vpt.pop_back(); 53 } 54 if (pt.x
::reverse_iterator vptit;101 int x,y;102 DWORD dwLparam=0;103 DWORD *pdwLparam=&dwLparam;104 for (vptit=vpt.rbegin();vptit
x;107 y=vptit->y;108 __asm109 {110 PUSH EAX111 PUSH EBX112 PUSH ECX113 MOV EAX,x114 MOV EBX,y115 MOV ECX,pdwLparam116 MOV WORD PTR [ECX],AX117 ADD ECX,2118 MOV WORD PTR [ECX],BX119 POP ECX120 POP EBX121 POP EAX122 }123 SendMessage(hDst,WM_LBUTTONDOWN,1,dwLparam);124 SendMessage(hDst,WM_LBUTTONUP,0,dwLparam);125 }126 }127 128 //查找植物大战僵尸游戏主窗口。129 BOOL CALLBACK PCEnumWindows(HWND hwnd,LPARAM lparam)130 {131 TCHAR szTitle[256];132 RECT rtTmp;133 GetWindowText(hwnd,szTitle,256);134 if (lstrlen(szTitle)>0)135 {136 std::string strTitle=szTitle;137 if(strTitle.find("Plants vs.")!=std::string::npos)138 {139 GetWindowRect(hwnd,&rtTmp);140 if (rtTmp.left<0||rtTmp.top<0)141 {142 return true;143 }144 if (rtTmp.right-rtTmp.left>300)145 {146 hDst=hwnd;147 rtDst=rtTmp;148 }149 }150 }151 return true;152 }153 154 void PC2ButtonStart(HWND hwnd)155 {156 if (bBeg)157 {158 KillTimer(hwnd,ID_PICKCOIN_TIMER);159 SetDlgItemText(hwnd,IDC_BUTTONSTART,szStart);160 } 161 else162 {163 if (vpt.size()<2)164 {165 MessageBox(hwnd,szPointNotComeplete,szOperateTip,MB_OK|MB_ICONERROR);166 return;167 }168 SetTimer(hwnd,ID_PICKCOIN_TIMER,PICKCOIN_TIMESPAN,NULL);169 SetDlgItemText(hwnd,IDC_BUTTONSTART,szStop);170 }171 bBeg=!bBeg;172 }173 174 void PC2ComputePoint(HWND hwnd)175 {176 POINT ptLU,ptRD,ptTmp;177 int i,j;178 if (bCompute)179 {180 vpt.clear();181 SetDlgItemText(hwnd,IDC_STATICLU,TEXT("(0,0)"));182 SetDlgItemText(hwnd,IDC_STATICRD,TEXT("(0,0)"));183 SetDlgItemText(hwnd,IDC_BUTTONCOMPUTE,szComputePoint);184 } 185 else186 {187 if (vpt.size()<2)188 {189 MessageBox(hwnd,szPointNotComeplete,szOperateTip,MB_OK|MB_ICONERROR);190 return;191 }192 ptLU=vpt[0];193 ptRD=vpt[1];194 vpt.clear();195 for (i=ptLU.x;i

 

转载于:https://www.cnblogs.com/xuesongshu/archive/2013/01/19/2867178.html

你可能感兴趣的文章
Python 面向对象(其四)
查看>>
客户端访问浏览器的流程
查看>>
Linux——ls
查看>>
操作系统(八) 死锁
查看>>
codeforces水题100道 第二十二题 Codeforces Beta Round #89 (Div. 2) A. String Task (strings)
查看>>
c++||template
查看>>
[BZOJ 5323][Jxoi2018]游戏
查看>>
编程面试的10大算法概念汇总
查看>>
Vue
查看>>
表变量与临时表的优缺点(转)
查看>>
shell脚本图书
查看>>
UNIX环境高级编程——线程限制
查看>>
UNIX网络编程——原始套接字SOCK_RAW
查看>>
TCP发送源码学习(1)--tcp_sendmsg
查看>>
使用两个不同类型的数据进行加法计算时,使用异常处理语句捕获由于数据类型错误而出现的异常,发生生成错误。是否继续并运行上次的成功生成?...
查看>>
python-三级菜单和购物车程序
查看>>
web开发灵感推荐--34个有吸引力的电影网站设计灵感
查看>>
sql操作
查看>>
条件断点 符号断点
查看>>
第二十三模板 18.3.5 位集合
查看>>