Parcourir la source

镜妖单例版本,成功率达80%。

Jeff il y a 4 ans
Parent
commit
2c35c721f8

+ 239 - 243
GameAssist/GameAssist/Assist.cpp

@@ -113,7 +113,7 @@ namespace GAssist
 
 	void GetGameConfig()
 	{
-		TCHAR szValue[MAX_PATH] = {0};
+		TCHAR szValue[MAX_PATH] = { 0 };
 		GetPrivateProfileString(_T("Assist"), _T("GamePath"), _T(""), szValue, MAX_PATH, g_szAssistConfig);
 		g_strGameDir = szValue;
 		GetPrivateProfileString(_T("Assist"), _T("GameApp"), _T(""), g_szGameApp, MAX_PATH, g_szAssistConfig);
@@ -192,9 +192,9 @@ namespace GAssist
 	{
 		DWORD dwPID = 0;
 		HWND hwndRet = NULL;
-		TCHAR szName[MAX_PATH] = {0};
-		TCHAR szClass[MAX_PATH] = {0};
-		TCHAR szLogMsg[MAX_PATH] = {0};
+		TCHAR szName[MAX_PATH] = { 0 };
+		TCHAR szClass[MAX_PATH] = { 0 };
+		TCHAR szLogMsg[MAX_PATH] = { 0 };
 		// 取得第一个窗口句柄
 		HWND hwndWindow = ::GetTopWindow(NULL);
 		// 遍历出结果窗口;
@@ -210,11 +210,11 @@ namespace GAssist
 					// 获取窗口类名,标题名;
 					::GetWindowText(hwndRet, szName, sizeof(szName) / sizeof(TCHAR));
 					::GetClassName(hwndRet, szClass, sizeof(szClass) / sizeof(TCHAR)); // 窗口类
-					
+
 					TRACE3(_T("类名:%s 标题:%s 地址%p\n"), szClass, szName, hwndRet);
 
 					// 是否找到目前窗口;
-					if ( _tcsstr(szName, _T("大话水浒")) )
+					if (_tcsstr(szName, _T("大话水浒")))
 						break;
 				}
 			}
@@ -222,7 +222,7 @@ namespace GAssist
 			hwndWindow = ::GetNextWindow(hwndWindow, GW_HWNDNEXT);
 		}
 
-		
+
 		// 上面取得的窗口,不一定是最上层的窗口,需要通过GetParent获取最顶层窗口
 		HWND hwndWindowParent = NULL;
 		// 循环查找父窗口,以便保证返回的句柄是最顶层的窗口句柄
@@ -243,19 +243,19 @@ namespace GAssist
 		return hwndRet;
 	}
 
-	
+
 	DWORD GetProcessId(LPCTSTR lpProcessName /* = _T("Game.exe") */)
 	{
 		DWORD dwProcessId = 0;
 		PROCESSENTRY32	pe32 = { 0 };
 
 		HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
-		if ( hProcessSnap == NULL ) return 0;
+		if (hProcessSnap == NULL) return 0;
 
 		// 遍历进程;
 		pe32.dwSize = sizeof(PROCESSENTRY32);
-		for ( BOOL bRet = Process32First(hProcessSnap, &pe32); bRet; bRet = Process32Next(hProcessSnap, &pe32) ) {
-			if ( _tcscmp(lpProcessName, pe32.szExeFile) == 0 ) {
+		for (BOOL bRet = Process32First(hProcessSnap, &pe32); bRet; bRet = Process32Next(hProcessSnap, &pe32)) {
+			if (_tcscmp(lpProcessName, pe32.szExeFile) == 0) {
 				dwProcessId = pe32.th32ProcessID;
 				break;
 			}
@@ -266,7 +266,7 @@ namespace GAssist
 		return dwProcessId;
 	}
 
-	HWND GetProcessMainWnd(const DWORD &dwTagetProcessId, LPCTSTR lpTagetWndName /* = _T("大话水浒") */)
+	HWND GetProcessMainWnd(const DWORD& dwTagetProcessId, LPCTSTR lpTagetWndName /* = _T("大话水浒") */)
 	{
 		DWORD dwCurPorcessId = 0;
 		HWND hTagetProcessWnd = NULL;
@@ -274,29 +274,29 @@ namespace GAssist
 		TCHAR szClassName[MAX_PATH] = { 0 };
 
 		// 取得第一个窗口句柄;
-		for ( HWND hCurWnd = ::GetTopWindow(NULL); hCurWnd != NULL; hCurWnd = ::GetNextWindow(hCurWnd, GW_HWNDNEXT) ) {
+		for (HWND hCurWnd = ::GetTopWindow(NULL); hCurWnd != NULL; hCurWnd = ::GetNextWindow(hCurWnd, GW_HWNDNEXT)) {
 			// 重置为0;
 			dwCurPorcessId = 0;
 			// 通过窗口句柄反查进程pid;
 			DWORD dwThreadId = ::GetWindowThreadProcessId(hCurWnd, &dwCurPorcessId);
-			if ( dwThreadId != 0 ) {
+			if (dwThreadId != 0) {
 				// 判断当前进程id是否和目标进程id相同;
-				if ( dwCurPorcessId == dwTagetProcessId ) {
-					if ( lpTagetWndName == NULL ) {
+				if (dwCurPorcessId == dwTagetProcessId) {
+					if (lpTagetWndName == NULL) {
 						hTagetProcessWnd = hCurWnd;
 						break;
 					}
-					else{
+					else {
 						// 获取窗口名称;
-						::GetWindowText(hCurWnd, szWndName, sizeof(szWndName)/sizeof(TCHAR));
+						::GetWindowText(hCurWnd, szWndName, sizeof(szWndName) / sizeof(TCHAR));
 						// 获取窗口类名;
-						::GetClassName(hCurWnd, szClassName, sizeof(szClassName)/sizeof(TCHAR));
+						::GetClassName(hCurWnd, szClassName, sizeof(szClassName) / sizeof(TCHAR));
 #ifdef _DEBUG
-						TCHAR szLogMsg[MAX_PATH] = {0};
+						TCHAR szLogMsg[MAX_PATH] = { 0 };
 						_stprintf_s(szLogMsg, _T("类名:%s, 窗口名:%s,窗口地址:%p \n"), szClassName, szWndName, hCurWnd);
 						OutputDebugString(szLogMsg);
 #endif
-						if ( _tcsstr(szWndName, lpTagetWndName) != NULL ) {
+						if (_tcsstr(szWndName, lpTagetWndName) != NULL) {
 							hTagetProcessWnd = hCurWnd;
 							break;
 						}
@@ -307,9 +307,9 @@ namespace GAssist
 
 		// 当前窗口有可能不是进程父窗口;
 		HWND hParentWnd = hTagetProcessWnd;
-		while ( hParentWnd ) {
+		while (hParentWnd) {
 			hParentWnd = ::GetParent(hTagetProcessWnd);
-			if ( hParentWnd == NULL )
+			if (hParentWnd == NULL)
 				break;
 			hTagetProcessWnd = hParentWnd;
 		}
@@ -321,23 +321,23 @@ namespace GAssist
 	{
 		HWND hTagetWnd = NULL;
 		DWORD dwProcessId = 0;
-		if ( (dwProcessId = GetProcessId(lpProcessName)) != 0 ) {
+		if ((dwProcessId = GetProcessId(lpProcessName)) != 0) {
 			hTagetWnd = GetProcessMainWnd(dwProcessId, lpTagetWndName);
 		}
 
 		return hTagetWnd;
 	}
-	
+
 	std::vector<GameHwnd> g_vtGameHwnd;
-	BOOL CALLBACK EnumChildWindowCallBack(HWND hWnd, LPARAM lParam)  
-	{  
-		DWORD dwPid = 0;  
+	BOOL CALLBACK EnumChildWindowCallBack(HWND hWnd, LPARAM lParam)
+	{
+		DWORD dwPid = 0;
 		GetWindowThreadProcessId(hWnd, &dwPid); // 获得找到窗口所属的进程   
 		if (dwPid == lParam) // 判断是否是目标进程的窗口   
-		{  
-			TCHAR szName[MAX_PATH] = {0};
-			TCHAR szClass[MAX_PATH] = {0};
-			TCHAR szLogMsg[MAX_PATH] = {0};
+		{
+			TCHAR szName[MAX_PATH] = { 0 };
+			TCHAR szClass[MAX_PATH] = { 0 };
+			TCHAR szLogMsg[MAX_PATH] = { 0 };
 			::GetWindowText(hWnd, szName, sizeof(szName) / sizeof(TCHAR));
 			::GetClassName(hWnd, szClass, sizeof(szClass) / sizeof(TCHAR)); // 窗口类
 			DWORD dwId = ::GetDlgCtrlID(hWnd);
@@ -352,19 +352,19 @@ namespace GAssist
 			ghwnd.strClassName = szClass;
 			g_vtGameHwnd.push_back(ghwnd);
 
-			_tprintf_s(_T("0x%08X    ") , hWnd); // 输出窗口信息   
-			TCHAR buf[MAX_PATH];  
-			SendMessage(hWnd, WM_GETTEXT, MAX_PATH, (LPARAM)buf);  
-			_tprintf_s(_T("%s/n") , buf);
+			_tprintf_s(_T("0x%08X    "), hWnd); // 输出窗口信息   
+			TCHAR buf[MAX_PATH];
+			SendMessage(hWnd, WM_GETTEXT, MAX_PATH, (LPARAM)buf);
+			_tprintf_s(_T("%s/n"), buf);
 			EnumChildWindows(hWnd, EnumChildWindowCallBack, lParam);    // 递归查找子窗口   
-		}  
-		return  TRUE;  
-	}  
+		}
+		return  TRUE;
+	}
 
 	// nStartCount:启动进程数量;
 	void StartGame(std::string strGameDir)
 	{
-		if ( !PathFileExists(strGameDir.c_str()) )
+		if (!PathFileExists(strGameDir.c_str()))
 			return;
 
 		SetCurrentDirectory(strGameDir.c_str());
@@ -373,55 +373,55 @@ namespace GAssist
 		Sleep(1500); // Main.exe设置了陷阱(自己再开启了一个进程,结束上一个进程),需要等1.5秒;
 
 		DWORD dwProcId = GAssist::FindProcess(_T("Main.exe"));
-		if ( dwProcId <= 0 )
+		if (dwProcId <= 0)
 			return;
-		
+
 		EnumWindows(GAssist::EnumChildWindowCallBack, dwProcId);
-		if ( GAssist::g_vtGameHwnd.size() ) {
+		if (GAssist::g_vtGameHwnd.size()) {
 			int nStatus = 0;
 			GAssist::GameHwnd* gp = NULL;
 			GAssist::GameHwnd* gbmin = NULL;
 			GAssist::GameHwnd* gbentry = NULL;
-			for ( std::vector<GAssist::GameHwnd>::iterator it = GAssist::g_vtGameHwnd.begin(); it != GAssist::g_vtGameHwnd.end(); it++ )
+			for (std::vector<GAssist::GameHwnd>::iterator it = GAssist::g_vtGameHwnd.begin(); it != GAssist::g_vtGameHwnd.end(); it++)
 			{
-				if ( nStatus >= 3 )
+				if (nStatus >= 3)
 					break;
 
-				if ( _tcsicmp(it->strWinText.c_str(), _T("最小化")) == 0 )
+				if (_tcsicmp(it->strWinText.c_str(), _T("最小化")) == 0)
 				{
 					gbmin = &*it;
 					nStatus++;
 				}
 
-				if ( _tcsicmp(it->strWinText.c_str(), _T("大话水浒")) == 0 )
+				if (_tcsicmp(it->strWinText.c_str(), _T("大话水浒")) == 0)
 				{
 					gp = &*it;
 					nStatus++;
 				}
 
-				if ( _tcsicmp(it->strWinText.c_str(), _T("进入游戏")) == 0 )
+				if (_tcsicmp(it->strWinText.c_str(), _T("进入游戏")) == 0)
 				{
 					gbentry = &*it;
 					nStatus++;
 				}
 			}
 
-			if ( gp && gbentry && gbmin) {
+			if (gp && gbentry && gbmin) {
 				// 发送点击事件;
 				// 先最小化;
-				::SendMessage(gp->hwnd,WM_COMMAND,gbmin->dwId,NULL);
+				::SendMessage(gp->hwnd, WM_COMMAND, gbmin->dwId, NULL);
 				// 再进入;
-				::SendMessage(gp->hwnd,WM_COMMAND,gbentry->dwId,NULL);
+				::SendMessage(gp->hwnd, WM_COMMAND, gbentry->dwId, NULL);
 			}
 		}
 	}
-	
+
 	// 使用WM_LBUTTONDBLCLK完全无效;
 	void MouseClick(HWND hwnd, POINT pt, BOOL bClientRect)
 	{
-		if ( !IsWindow(hwnd) )
+		if (!IsWindow(hwnd))
 			return;
-		
+
 		::ShowWindow(hwnd, SW_SHOWNORMAL);
 		::SetForegroundWindow(hwnd); // 窗口前置才能单击成功;
 #if 0 // 使用Post或Send的方式,鼠标是不会显示出来的;
@@ -429,7 +429,7 @@ namespace GAssist
 		::PostMessage(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(pt.x, pt.y));
 #else// 建议使用这种方式,可以看到鼠标;
 		POINT ptScreen = pt;
-		if ( bClientRect )
+		if (bClientRect)
 			ClientToScreen(hwnd, &ptScreen);
 		::SetCursorPos(ptScreen.x, ptScreen.y); // 必须将鼠标定位到目标单击点;
 		mouse_event(MOUSEEVENTF_LEFTDOWN, ptScreen.x, ptScreen.y, 0, 0);
@@ -440,7 +440,7 @@ namespace GAssist
 
 	void MouseDbClick(HWND hwnd, POINT pt)
 	{
-		if ( !IsWindow(hwnd) )
+		if (!IsWindow(hwnd))
 			return;
 
 		::ShowWindow(hwnd, SW_SHOWNORMAL);
@@ -505,7 +505,7 @@ namespace GAssist
 
 	void MouseClick(HWND hwnd, unsigned int x, unsigned int y)
 	{
-		if ( !IsWindow(hwnd) )
+		if (!IsWindow(hwnd))
 			return;
 
 		::ShowWindow(hwnd, SW_SHOWNORMAL);
@@ -514,7 +514,7 @@ namespace GAssist
 		::PostMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y));
 		::PostMessage(hwnd, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
 #else
-		POINT ptScreen = {x,y};
+		POINT ptScreen = { x,y };
 		ClientToScreen(hwnd, &ptScreen);
 		::SetCursorPos(ptScreen.x, ptScreen.y);
 		mouse_event(MOUSEEVENTF_LEFTDOWN, ptScreen.x, ptScreen.y, 0, 0);
@@ -525,7 +525,7 @@ namespace GAssist
 
 	void MouseMove(HWND hwnd, POINT pt)
 	{
-		if ( !IsWindow(hwnd) )
+		if (!IsWindow(hwnd))
 			return;
 
 		::PostMessage(hwnd, WM_MOUSEMOVE, MK_LBUTTON, MAKELPARAM(pt.x, pt.y));
@@ -534,7 +534,7 @@ namespace GAssist
 
 	void MouseMove(HWND hwnd, POINT ptStart, POINT ptEnd)
 	{
-		if ( !IsWindow(hwnd) )
+		if (!IsWindow(hwnd))
 			return;
 
 		//::SendMessage(hwnd, WM_MOUSEMOVE, MK_LBUTTON, lparam);
@@ -543,7 +543,7 @@ namespace GAssist
 
 #if 1
 		// 计算个中间点;
-		POINT ptMid = { (ptStart.x + ptEnd.x) / 2, (ptStart.y + ptEnd.y) / 2};
+		POINT ptMid = { (ptStart.x + ptEnd.x) / 2, (ptStart.y + ptEnd.y) / 2 };
 		::PostMessage(hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(ptMid.x, ptMid.y));
 		Sleep(200);
 #endif
@@ -556,7 +556,7 @@ namespace GAssist
 	// 最后一步直接单击;
 	void MouseMoveEx(HWND hwnd, POINT ptStart, POINT ptEnd)
 	{
-		if ( !IsWindow(hwnd) )
+		if (!IsWindow(hwnd))
 			return;
 
 		//::SendMessage(hwnd, WM_MOUSEMOVE, MK_LBUTTON, lparam);
@@ -565,7 +565,7 @@ namespace GAssist
 
 #if 1
 		// 计算个中间点;
-		POINT ptMid = { (ptStart.x + ptEnd.x) / 2, (ptStart.y + ptEnd.y) / 2};
+		POINT ptMid = { (ptStart.x + ptEnd.x) / 2, (ptStart.y + ptEnd.y) / 2 };
 		::PostMessage(hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(ptMid.x, ptMid.y));
 		Sleep(200);
 #endif
@@ -578,9 +578,9 @@ namespace GAssist
 
 	void DragMouse(HWND hwnd, POINT ptStart, POINT ptEnd)
 	{
-		if ( !IsWindow(hwnd) )
+		if (!IsWindow(hwnd))
 			return;
-		
+
 		::ShowWindow(hwnd, SW_SHOWNORMAL);
 		::SetForegroundWindow(hwnd);
 #if 0
@@ -617,7 +617,7 @@ namespace GAssist
 		mouse_event(MOUSEEVENTF_LEFTDOWN, ptSStart.x, ptSStart.y, 0, 0);
 		Sleep(1200);//必须暂停1秒左右,拖动才有效;
 		// MOUSEEVENTF_ABSOLUTE 使用绝对鼠标位置;
-		mouse_event(MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE, ptSEnd.x, ptSEnd.y, 0, 0);
+		mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, ptSEnd.x, ptSEnd.y, 0, 0);
 		Sleep(500);
 		mouse_event(MOUSEEVENTF_LEFTUP, ptSEnd.x, ptSEnd.y, 0, 0);
 #endif
@@ -625,43 +625,43 @@ namespace GAssist
 
 	void SendKey(HWND hwnd, DWORD key, BOOL bCtrl /* = FALSE */, BOOL bAtl /* = FALSE */, BOOL bShift /* = FALSE */)
 	{
-		if ( !IsWindow(hwnd) )
+		if (!IsWindow(hwnd))
 			return;
 
 		::ShowWindow(hwnd, SW_SHOWNORMAL);
 		::SetForegroundWindow(hwnd);
 
-		if ( bCtrl)
-			keybd_event(VK_CONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | 0,0 );
-		if ( bAtl )
-			keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | 0,0 );
-		if ( bShift )
-			keybd_event(VK_SHIFT, 0x2A, KEYEVENTF_EXTENDEDKEY | 0,0 );
+		if (bCtrl)
+			keybd_event(VK_CONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | 0, 0);
+		if (bAtl)
+			keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
+		if (bShift)
+			keybd_event(VK_SHIFT, 0x2A, KEYEVENTF_EXTENDEDKEY | 0, 0);
 		Sleep(120);	// 注意:有些电脑能响应Ctrl+V,有些不行,则需要加大CTRL与V之间的时间间隔;
 		// key down;
-		keybd_event(key, 0, KEYEVENTF_EXTENDEDKEY | 0,0 );
+		keybd_event(key, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
 		// key up;
-		keybd_event(key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0 );
+		keybd_event(key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
 		Sleep(120);
-		if ( bCtrl )
-			keybd_event(VK_CONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0 );
-		if ( bAtl )
-			keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0 );
-		if ( bShift )
-			keybd_event(VK_SHIFT, 0x2A, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0 );
+		if (bCtrl)
+			keybd_event(VK_CONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
+		if (bAtl)
+			keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
+		if (bShift)
+			keybd_event(VK_SHIFT, 0x2A, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
 	}
 
 	BOOL SetClipboardString(const char* lpString)
 	{
-		if ( lpString == NULL || lpString[0] == '\0' )
+		if (lpString == NULL || lpString[0] == '\0')
 			return FALSE;
 
-		if ( OpenClipboard(NULL) )
+		if (OpenClipboard(NULL))
 		{
 			HGLOBAL hClipString;
 			EmptyClipboard();
 			hClipString = GlobalAlloc(GMEM_DDESHARE, _tcslen(lpString) + 1);
-			char *lpBuffer = (char*)GlobalLock(hClipString);
+			char* lpBuffer = (char*)GlobalLock(hClipString);
 			_tcscpy_s(lpBuffer, _tcslen(lpString) + 1, lpString);
 			GlobalUnlock(hClipString);
 			SetClipboardData(CF_TEXT, hClipString);
@@ -675,12 +675,12 @@ namespace GAssist
 
 	CString GetClipboradString(/*char *pString, const int len*/)
 	{
-		if ( OpenClipboard(NULL) )
+		if (OpenClipboard(NULL))
 		{
 			HANDLE hData = GetClipboardData(CF_TEXT);
-			if ( hData )
+			if (hData)
 			{
-				char *lpBuffer = (char*)GlobalLock(hData);
+				char* lpBuffer = (char*)GlobalLock(hData);
 				//memcpy(pString, lpBuffer, len);
 				CString str(lpBuffer);
 				GlobalUnlock(hData);
@@ -696,7 +696,7 @@ namespace GAssist
 	// 截图;
 	HBITMAP CopyDC2Bitmap(HWND hWnd, LPRECT lpRect)
 	{
-		if ( !lpRect || IsRectEmpty(lpRect) )
+		if (!lpRect || IsRectEmpty(lpRect))
 			return NULL;
 
 		HDC hWndDC = ::GetWindowDC(hWnd);
@@ -721,7 +721,7 @@ namespace GAssist
 		hMenBitmap = CreateCompatibleBitmap(hWndDC, nWidth, nHeight);
 
 		hOldBitmap = (HBITMAP)SelectObject(hMemDC, hMenBitmap);
-		::PrintWindow(hWnd, hMemDC, 0);  
+		::PrintWindow(hWnd, hMemDC, 0);
 		// 将窗口DC内存复制到兼容DC上;
 		StretchBlt(hMemDC, 0, 0, nWidth, nHeight, hWndDC, left, top, nWidth, nHeight, SRCCOPY);
 		//BitBlt(hMemDC, 0, 0, nWidth, nHeight, hWndDC, left, top, SRCCOPY);
@@ -736,105 +736,101 @@ namespace GAssist
 	BOOL SaveBitmap(HBITMAP hBitmpa, std::string strSavePath)
 	{
 		//把位图的信息保存到bmpinfo;    
-		BITMAP bmpinfo;    
-		GetObject(hBitmpa,sizeof(BITMAP),&bmpinfo);    
-		DWORD dwBmBitsSize = ((bmpinfo.bmWidth * 32+31)/32) * 4 * bmpinfo.bmHeight;     
+		BITMAP bmpinfo;
+		GetObject(hBitmpa, sizeof(BITMAP), &bmpinfo);
+		DWORD dwBmBitsSize = ((bmpinfo.bmWidth * 32 + 31) / 32) * 4 * bmpinfo.bmHeight;
 		//位图文件头 14字节    
-		BITMAPFILEHEADER bf;    
-		bf.bfType      = 0x4D42;                  
+		BITMAPFILEHEADER bf;
+		bf.bfType = 0x4D42;
 		//BM    
-		bf.bfSize      = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwBmBitsSize;     
-		bf.bfReserved1 = 0;     
-		bf.bfReserved2 = 0;     
-		bf.bfOffBits   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);     
+		bf.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwBmBitsSize;
+		bf.bfReserved1 = 0;
+		bf.bfReserved2 = 0;
+		bf.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
 		//位图信息头    
-		BITMAPINFOHEADER bi;    
-		bi.biSize          = sizeof(BITMAPINFOHEADER);    
-		bi.biWidth         = bmpinfo.bmWidth;    
-		bi.biHeight        = bmpinfo.bmHeight;    
-		bi.biPlanes        = 1;    
-		bi.biBitCount      = 32;    
-		bi.biCompression   = BI_RGB;    
-		bi.biSizeImage     = 0;    
-		bi.biXPelsPerMeter = 0;    
-		bi.biYPelsPerMeter = 0;    
-		bi.biClrUsed       = 8;    
-		bi.biClrImportant  = 0;    
+		BITMAPINFOHEADER bi;
+		bi.biSize = sizeof(BITMAPINFOHEADER);
+		bi.biWidth = bmpinfo.bmWidth;
+		bi.biHeight = bmpinfo.bmHeight;
+		bi.biPlanes = 1;
+		bi.biBitCount = 32;
+		bi.biCompression = BI_RGB;
+		bi.biSizeImage = 0;
+		bi.biXPelsPerMeter = 0;
+		bi.biYPelsPerMeter = 0;
+		bi.biClrUsed = 8;
+		bi.biClrImportant = 0;
 		//位图数据;    
 		char* context = new char[dwBmBitsSize];
-		HDC dc  = ::GetDC(NULL);    
-		GetDIBits(dc, hBitmpa, 0, bi.biHeight, context, (BITMAPINFO*)&bi, DIB_RGB_COLORS);    
-		FILE* f = fopen(strSavePath.c_str(),"wb");    
-		fwrite((char*)&bf,sizeof(BITMAPFILEHEADER),1,f);    
-		fwrite((char*)&bi,sizeof(BITMAPINFOHEADER),1,f);    
-		fwrite(context,dwBmBitsSize,1,f);    
-		fclose(f);    
-		delete context;    
-		::ReleaseDC(NULL,dc);    
-		return 0;    
+		HDC dc = ::GetDC(NULL);
+		GetDIBits(dc, hBitmpa, 0, bi.biHeight, context, (BITMAPINFO*)&bi, DIB_RGB_COLORS);
+		FILE* f = fopen(strSavePath.c_str(), "wb");
+		fwrite((char*)&bf, sizeof(BITMAPFILEHEADER), 1, f);
+		fwrite((char*)&bi, sizeof(BITMAPINFOHEADER), 1, f);
+		fwrite(context, dwBmBitsSize, 1, f);
+		fclose(f);
+		delete context;
+		::ReleaseDC(NULL, dc);
+		return 0;
 	}
 
 	void SaveHwndToBmpFile(HWND hWnd, std::string strSavePath) {
-		HDC hDC = ::GetWindowDC(hWnd); 	
-		ASSERT(hDC); 	 	
-		HDC hMemDC = ::CreateCompatibleDC(hDC); 	
-		ASSERT(hMemDC); 	 	
-
-		RECT rc; 	
-		::GetWindowRect(hWnd, &rc);  	
-		HBITMAP hBitmap = ::CreateCompatibleBitmap(hDC, rc.right - rc.left, rc.bottom - rc.top); 	
-
-		ASSERT(hBitmap); 	 	
-		HBITMAP hOldBmp = (HBITMAP)::SelectObject(hMemDC, hBitmap); 	
-		::PrintWindow(hWnd, hMemDC, 0);  	
-		BITMAP bitmap = {0}; 	
-		::GetObject(hBitmap, sizeof(BITMAP), &bitmap); 	
-		BITMAPINFOHEADER bi = {0}; 	
-		BITMAPFILEHEADER bf = {0};  	
-		CONST int nBitCount = 24; 	
-		bi.biSize = sizeof(BITMAPINFOHEADER); 	
-		bi.biWidth = bitmap.bmWidth; 	
-		bi.biHeight = bitmap.bmHeight; 	
-		bi.biPlanes = 1; 	
-		bi.biBitCount = nBitCount; 	
-		bi.biCompression = BI_RGB; 	
-		DWORD dwSize = ((bitmap.bmWidth * nBitCount + 31) / 32) * 4 * bitmap.bmHeight;  	
-		HANDLE hDib = GlobalAlloc(GHND, dwSize + sizeof(BITMAPINFOHEADER)); 	
-		LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib); 	
-		*lpbi = bi;  	
-		::GetDIBits(hMemDC, hBitmap, 0, bitmap.bmHeight, (BYTE*)lpbi + sizeof(BITMAPINFOHEADER), (BITMAPINFO*)lpbi, DIB_RGB_COLORS);  	
-		try 	
-		{ 		
-			CFile file; 		
-			file.Open(strSavePath.c_str(), CFile::modeCreate | CFile::modeWrite);
-			bf.bfType = 0x4d42; 		
-			dwSize += sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); 		
-			bf.bfSize = dwSize; 		
-			bf.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);  		
-			file.Write((BYTE*)&bf, sizeof(BITMAPFILEHEADER)); 		
-			file.Write((BYTE*)lpbi, dwSize); 		
-			file.Close(); 	
-		} 	
-		catch(CFileException* e) 	
-		{ 		
-			e->ReportError(); 		
-			e->Delete(); 	
-		}  	
-		GlobalUnlock(hDib); 	
-		GlobalFree(hDib);  	
-		::SelectObject(hMemDC, hOldBmp); 	
-		::DeleteObject(hBitmap);	 	
-		::DeleteObject(hMemDC); 	
-		::ReleaseDC(hWnd, hDC); 
+		HDC hDC = ::GetWindowDC(hWnd);
+		ASSERT(hDC);
+		HDC hMemDC = ::CreateCompatibleDC(hDC);
+		ASSERT(hMemDC);
+
+		RECT rc;
+		::GetWindowRect(hWnd, &rc);
+		HBITMAP hBitmap = ::CreateCompatibleBitmap(hDC, rc.right - rc.left, rc.bottom - rc.top);
+
+		ASSERT(hBitmap);
+		HBITMAP hOldBmp = (HBITMAP)::SelectObject(hMemDC, hBitmap);
+		::PrintWindow(hWnd, hMemDC, 0);
+		BITMAP bitmap = { 0 };
+		::GetObject(hBitmap, sizeof(BITMAP), &bitmap);
+		BITMAPINFOHEADER bi = { 0 };
+		BITMAPFILEHEADER bf = { 0 };
+		CONST int nBitCount = 24;
+		bi.biSize = sizeof(BITMAPINFOHEADER);
+		bi.biWidth = bitmap.bmWidth;
+		bi.biHeight = bitmap.bmHeight;
+		bi.biPlanes = 1;
+		bi.biBitCount = nBitCount;
+		bi.biCompression = BI_RGB;
+		DWORD dwSize = ((bitmap.bmWidth * nBitCount + 31) / 32) * 4 * bitmap.bmHeight;
+		HANDLE hDib = GlobalAlloc(GHND, dwSize + sizeof(BITMAPINFOHEADER));
+		LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib);
+		*lpbi = bi;
+		::GetDIBits(hMemDC, hBitmap, 0, bitmap.bmHeight, (BYTE*)lpbi + sizeof(BITMAPINFOHEADER), (BITMAPINFO*)lpbi, DIB_RGB_COLORS);
+
+		CFile file;
+		CFileException fep;
+		if (file.Open(strSavePath.c_str(), CFile::modeCreate | CFile::modeWrite, &fep)) {
+			bf.bfType = 0x4d42;
+			dwSize += sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
+			bf.bfSize = dwSize;
+			bf.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
+			file.Write((BYTE*)&bf, sizeof(BITMAPFILEHEADER));
+			file.Write((BYTE*)lpbi, dwSize);
+			file.Close();
+		}
+
+		GlobalUnlock(hDib);
+		GlobalFree(hDib);
+		::SelectObject(hMemDC, hOldBmp);
+		::DeleteObject(hBitmap);
+		::DeleteObject(hMemDC);
+		::ReleaseDC(hWnd, hDC);
 
 		Sleep(30);
-	}  
+	}
 
 
-// 	#include <D3D9.h>
-// 	#include <D3dx9tex.h>
-// 	#pragma comment(lib, "D3dx9.lib")
-	//#include <d3d9helper>
+	// 	#include <D3D9.h>
+	// 	#include <D3dx9tex.h>
+	// 	#pragma comment(lib, "D3dx9.lib")
+		//#include <d3d9helper>
 	BOOL ScreenShot(LPDIRECT3DDEVICE9 lpDevice, HWND hWnd, TCHAR* fileName)
 	{
 		HRESULT hr;
@@ -879,50 +875,50 @@ namespace GAssist
 	}
 
 	// 判断窗口是否被遮住;
-	bool IsCoveredByOtherWindow(HWND  hWnd) 
-	{ 
-		RECT rcTarget; 
+	bool IsCoveredByOtherWindow(HWND  hWnd)
+	{
+		RECT rcTarget;
 		GetWindowRect(hWnd, &rcTarget);
-		bool isChild = (WS_CHILD == (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)); 
+		bool isChild = (WS_CHILD == (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD));
 
-		if ( GetDesktopWindow() == hWnd )
+		if (GetDesktopWindow() == hWnd)
 			hWnd = GetWindow(GetTopWindow(hWnd), GW_HWNDLAST);
 
-		do 
-		{ 
-			HWND hCurWnd = hWnd; 
-			while ( NULL != (hWnd = GetNextWindow(hWnd, GW_HWNDPREV) )) 
-			{ 
+		do
+		{
+			HWND hCurWnd = hWnd;
+			while (NULL != (hWnd = GetNextWindow(hWnd, GW_HWNDPREV)))
+			{
 				//过滤了非窗口,没有显示的,无效的,非windows工具栏,置顶的窗口。如果不过滤非工具栏的句柄,那么会得到一些奇怪的窗口,会很难判断是否被遮住。
 				//if ( IsWindow(hWnd) && IsWindowVisible(hWnd) && IsWindowEnabled(hWnd) && !(GetWindowLong(hWnd,GWL_EXSTYLE)& WS_EX_TOOLWINDOW) && !(GetWindowLong(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST)) 
-				if ( ::IsWindowVisible(hWnd) )
-				{ 
+				if (::IsWindowVisible(hWnd))
+				{
 					RECT rcWnd;
-					GetWindowRect(hWnd, &rcWnd); 
+					GetWindowRect(hWnd, &rcWnd);
 
-					if ( !((rcWnd.right < rcTarget.left) || (rcWnd.left > rcTarget.right) || 
-						(rcWnd.bottom < rcTarget.top) || (rcWnd.top > rcTarget.bottom)) ) 
-					{      
+					if (!((rcWnd.right < rcTarget.left) || (rcWnd.left > rcTarget.right) ||
+						(rcWnd.bottom < rcTarget.top) || (rcWnd.top > rcTarget.bottom)))
+					{
 						return true;
-					} 
-				} 
-			} 
-
-			if ( isChild )
-			{ 
-				hWnd = GetParent(hCurWnd); 
-				isChild = (WS_CHILD == (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)); 
-			} 
-			else 
-			{ 
+					}
+				}
+			}
+
+			if (isChild)
+			{
+				hWnd = GetParent(hCurWnd);
+				isChild = (WS_CHILD == (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD));
+			}
+			else
+			{
 				break;
-			} 
-		}while ( true );
+			}
+		} while (true);
 
 		return false;
 	}
 
-	BOOL OpenImage(std::string strImag, cv::Mat &img)
+	BOOL OpenImage(std::string strImag, cv::Mat& img)
 	{
 		if (!PathFileExists(strImag.c_str()))
 			return FALSE;
@@ -937,7 +933,7 @@ namespace GAssist
 		return TRUE;
 	}
 
-	BOOL SetImgThreshold(cv::Mat &srcImg, cv::Mat &thresholdImg, long nThresholdVal, long nMaxThresholdVal, int type)
+	BOOL SetImgThreshold(cv::Mat& srcImg, cv::Mat& thresholdImg, long nThresholdVal, long nMaxThresholdVal, int type)
 	{
 		if (srcImg.data == NULL)
 			return FALSE;
@@ -947,38 +943,38 @@ namespace GAssist
 
 		switch (type)
 		{
-			case 0://全局阀值;
-				{
-					// 转成灰阶图;
-					cv::cvtColor(srcImg, thresholdImg, cv::COLOR_BGR2GRAY);
-					// 再高斯模糊处理(滤波);
-					cv::GaussianBlur(thresholdImg, thresholdImg, cv::Size(5, 5), 0, 0);
-					// 二值化;//全局化指定的阀值与返回值相等;
-					double dRetVal = cv::threshold(thresholdImg, thresholdImg, nThresholdVal, nMaxThresholdVal, cv::THRESH_BINARY);
-				}
-				break;
-			case 1://自适应阀值;
-				{
-					// 转成灰阶图;
-					cv::cvtColor(srcImg, thresholdImg, cv::COLOR_BGR2GRAY);
-					// 再高斯模糊处理(滤波);
-					cv::GaussianBlur(thresholdImg, thresholdImg, cv::Size(3, 3), 0, 0);
-					// 自适应阀值;
-					cv::medianBlur(thresholdImg, thresholdImg, 3);
-					// 局部二值化;//blocksize一般取3、5、7
-					cv::adaptiveThreshold(thresholdImg, thresholdImg, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 3, 4.5);
-				}
-				break;
-			case 2:// otsu阀值;
-				{
-					cv::cvtColor(srcImg, thresholdImg, cv::COLOR_BGR2GRAY);
-					// 高斯模糊;
-					cv::GaussianBlur(thresholdImg, thresholdImg, cv::Size(3, 3), 0, 0);
-					cv::threshold(thresholdImg, thresholdImg, nThresholdVal, nMaxThresholdVal, cv::THRESH_BINARY | cv::THRESH_OTSU);
-				}
-				break;
-			default:
-				break;
+		case 0://全局阀值;
+		{
+			// 转成灰阶图;
+			cv::cvtColor(srcImg, thresholdImg, cv::COLOR_BGR2GRAY);
+			// 再高斯模糊处理(滤波);
+			cv::GaussianBlur(thresholdImg, thresholdImg, cv::Size(5, 5), 0, 0);
+			// 二值化;//全局化指定的阀值与返回值相等;
+			double dRetVal = cv::threshold(thresholdImg, thresholdImg, nThresholdVal, nMaxThresholdVal, cv::THRESH_BINARY);
+		}
+		break;
+		case 1://自适应阀值;
+		{
+			// 转成灰阶图;
+			cv::cvtColor(srcImg, thresholdImg, cv::COLOR_BGR2GRAY);
+			// 再高斯模糊处理(滤波);
+			cv::GaussianBlur(thresholdImg, thresholdImg, cv::Size(3, 3), 0, 0);
+			// 自适应阀值;
+			cv::medianBlur(thresholdImg, thresholdImg, 3);
+			// 局部二值化;//blocksize一般取3、5、7
+			cv::adaptiveThreshold(thresholdImg, thresholdImg, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 3, 4.5);
+		}
+		break;
+		case 2:// otsu阀值;
+		{
+			cv::cvtColor(srcImg, thresholdImg, cv::COLOR_BGR2GRAY);
+			// 高斯模糊;
+			cv::GaussianBlur(thresholdImg, thresholdImg, cv::Size(3, 3), 0, 0);
+			cv::threshold(thresholdImg, thresholdImg, nThresholdVal, nMaxThresholdVal, cv::THRESH_BINARY | cv::THRESH_OTSU);
+		}
+		break;
+		default:
+			break;
 		}
 
 		return TRUE;
@@ -1113,15 +1109,15 @@ namespace GAssist
 		// 是否大于最低匹配度;
 		return (lv_nMaxVal >= lowestMatchValue ? TRUE : FALSE);
 	}
-	
+
 	void ZhiYeDaTiaoZhan()
 	{
 		// 判断当前地图是否在应天府;
 		//// 是:打开世界地图,寻路到NPC;
 		//// 否:退出
-		
+
 		// 对话NPC,进入地图;
-		
+
 	}
-	
+
 }

+ 98 - 217
GameAssist/GameAssist/GameAssistDlg.cpp

@@ -132,7 +132,7 @@ BOOL IsWattingAttack(HWND hWnd)
 	// 指定区域进行二值化;
 	cv::Mat imgThreshold;
 	cv::Mat imgROI = srcImg(cv::Rect(350, 55, 50, 60));
-	cv::imwrite("IsWattingAttack-match.bmp", imgROI);
+	//cv::imwrite("IsWattingAttack-match.bmp", imgROI);
 	if (GAssist::SetImgThreshold(imgROI, imgThreshold, 150, 255))
 	{
 		if (imgThreshold.data) {
@@ -160,7 +160,7 @@ BOOL IsWattingAttack(HWND hWnd)
 				length = arcLength(*it, true); area = contourArea(*it);
 				if (length > 130 &&  area > 550.0)
 				{
-					DebugLog(_T("当前周长和面积:%lf, %lf"), length, area);
+					//DebugLog(_T("当前周长和面积:%lf, %lf"), length, area);
 					bIsAttack = TRUE;
 					break;
 				}
@@ -288,42 +288,35 @@ void BattleOnece(HWND hWnd, BOOL bHasSummoner)
 // 与镜妖战斗;
 void BattleJY(HWND hWnd, BOOL bHasSummoner)
 {
-	if (IsBattle(hWnd)) { // 是否在战斗中;
-		SRAND(300, 500);
+	BOOL bFirstAttack = TRUE;
+	while (IsBattle(hWnd)) { // 是否在战斗中;
 		// 是否我方攻击;
-		BOOL bFirstAttack = FALSE;
-		while (IsWattingAttack(hWnd)) {
-			// 人物固定F1
-			// 根据角色选择技能;
-			GAssist::SendKey(hWnd, VK_F1);
-			SRAND(200, 300);
-			// 打镜妖喽罗;
-			GAssist::MouseClick(hWnd, CPoint(290 - 3, 140 - 20));
-			//GAssist::MouseMove(hWnd, CPoint(220 - 5, 180 - 10));// 打主镜妖;
-			SRAND(100, 200);
-
+		while (IsWattingAttack(hWnd)) { // Bug:如果被镜妖打死了,无法中断;
 			DebugLog(_T("BattleJY:我方攻击……"));
-			if (!bFirstAttack)
+			if (bFirstAttack)
 			{
+				SRAND(250, 300);
+				DebugLog(_T("BattleJY:第一次攻击……"));
 				// 根据角色选择技能;
 				GAssist::SendKey(hWnd, VK_F1);
-				SRAND(200, 300);
+				SRAND(300, 350);
 				// 打镜妖喽罗;
 				GAssist::MouseClick(hWnd, CPoint(290 - 3, 140 - 20));
 				//GAssist::MouseMove(hWnd, CPoint(220 - 5, 180 - 10));// 打主镜妖;
-				SRAND(200, 300);
+				SRAND(350, 500);
 
 				if (bHasSummoner) {
 					CRect rc;
 					// 召唤兽技能;
+					DebugLog(_T("BattleJY:召唤兽技能选择"));
 					if (GAssist::GetImgMatchtemplate(hWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\召唤兽技能选择.bmp"), rc))
 					{
 						SRAND(200, 500);
 						GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3), TRUE);
-						DebugLog(_T("BattleJY:召唤兽技能选择"));
+						//DebugLog(_T("BattleJY:召唤兽技能选择"));
 
 						// 选择重击;
-						SRAND(300, 800);
+						SRAND(100, 300);
 						if (GAssist::GetImgMatchtemplate(hWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\重击.bmp"), rc))
 						{
 							GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3), TRUE);
@@ -334,104 +327,103 @@ void BattleJY(HWND hWnd, BOOL bHasSummoner)
 						GAssist::MouseClick(hWnd, CPoint(290 - 3, 140 - 20));
 					}
 				}
-				else
-				{
-					GAssist::SendKey(hWnd, VK_A, FALSE, TRUE);
-					SRAND(600, 900);
-				}
 
-				bFirstAttack = TRUE;
+				bFirstAttack = FALSE;
 			}
 			else
 			{
+				DebugLog(_T("BattleJY:不是第一次攻击……"));
 				GAssist::SendKey(hWnd, VK_A, FALSE, TRUE);
-				SRAND(50, 100);
-				GAssist::SendKey(hWnd, VK_A, FALSE, TRUE);
-				SRAND(600, 900);
+				SRAND(80, 100);
+				if (bFirstAttack) {
+					GAssist::SendKey(hWnd, VK_A, FALSE, TRUE);
+					SRAND(80, 120);
+				}
 			}
-
-			SRAND(300, 550);
 		}
+
+		SRAND(500, 850);
 	}
-	else {
-		// 非战斗中,是否在贫民房中;
-		if (!IsOnMap(hWnd, _T("img\\地图\\贫民房.bmp"))) {
-			// 找小米;
-			CRect rc = FindNPC(hWnd, "臭美的小米");
+	
+	// 非战斗中,是否在贫民房中;
+	if (!IsOnMap(hWnd, _T("img\\地图\\贫民房.bmp"))) {
+		// 找小米;
+		CRect rc = FindNPC(hWnd, "臭美的小米");
 
-			// 选择进入;
-			BOOL bMatch = FALSE;
-			int trySize = 15;
-			// 我要挑战他们;
-			while (!(bMatch = ClickSetup(hWnd, _T("img\\活动\\镜妖\\1-我帮您抓.bmp")))) {
-				SRAND(800, 1200);
-				if (!trySize--) break;
-			}
+		// 选择进入;
+		BOOL bMatch = FALSE;
+		int trySize = 15;
+		// 我要挑战他们;
+		while (!(bMatch = ClickSetup(hWnd, _T("img\\活动\\镜妖\\1-我帮您抓.bmp")))) {
+			SRAND(800, 1200);
+			if (!trySize--) break;
+		}
 
-			if (bMatch) {
-				GAssist::MouseMove(hWnd, CPoint(rc.left, rc.top));
-				// 单击:我要挑战他们;
-				GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2), TRUE);
-				SRAND(1000, 1500);// 等出图;
+		if (bMatch) {
+			GAssist::MouseMove(hWnd, CPoint(rc.left, rc.top));
+			// 单击:我要挑战他们;
+			GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2), TRUE);
+			SRAND(1000, 1500);// 等出图;
 
-				// 移动一下;
-				GAssist::MouseMove(hWnd, CPoint(rc.left, rc.top));
-				::SetCursorPos(rc.left + rand() % 6, rc.top + rand() % 8);
+			// 移动一下;
+			GAssist::MouseMove(hWnd, CPoint(rc.left, rc.top));
+			::SetCursorPos(rc.left + rand() % 6, rc.top + rand() % 8);
 
-				// 是否第一次进入地图;
-				if (ClickSetup(hWnd, _T("img\\活动\\镜妖\\2-我这就去.bmp")))
+			// 是否第一次进入地图;
+			if (ClickSetup(hWnd, _T("img\\活动\\镜妖\\2-我这就去.bmp")))
+			{
+				SRAND(600, 1200);
+				if (ClickSetup(hWnd, _T("img\\活动\\镜妖\\3-战意镜妖.bmp")))
 				{
-					SRAND(600, 1200);
-					if (ClickSetup(hWnd, _T("img\\活动\\镜妖\\3-战意镜妖.bmp")))
+					SRAND(600, 1800);
+					if ((bMatch = ClickSetup(hWnd, _T("img\\活动\\镜妖\\4-我就选择它.bmp"))))
 					{
-						SRAND(600, 1800);
-						if ((bMatch = ClickSetup(hWnd, _T("img\\活动\\镜妖\\4-我就选择它.bmp"))))
-						{
-							SRAND(800, 1800);
-						}
+						SRAND(800, 1800);
 					}
 				}
 			}
 		}
-		else
+	}
+	else
+	{
+		// 找到镜妖;
+		CRect rc;
+		POINT spt[4] = { { 260, 360 }, { 300,390}, { 390, 350}, { 280,300 } };
+		for (int i = 0; !GAssist::GetImgMatchtemplate(hWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\镜妖3.bmp"), rc); i++)
 		{
-			// 找到镜妖;
-			CRect rc;
-			POINT spt[4] = { { 260, 360 }, { 300,390}, { 390, 350}, { 280,300 } };
-			for (int i = 0; !GAssist::GetImgMatchtemplate(hWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\镜妖3.bmp"), rc); i++)
-			{
-				// 打开世界地图;
-				GAssist::SendKey(hWnd, VK_TAB); SRAND(200, 300);
-				// 选择坐标点;
-				GAssist::MouseClick(hWnd, spt[i % 4]);
-				// 退出世界地图;
-				GAssist::SendKey(hWnd, VK_TAB); SRAND(500, 900);
-
-				if (i > 10) {
-					DebugLog(_T("未找到镜妖+10"));
-					break;
-				}
+			// 打开世界地图;
+			GAssist::SendKey(hWnd, VK_TAB); SRAND(200, 300);
+			// 选择坐标点;
+			GAssist::MouseClick(hWnd, spt[i % 4]);
+			// 退出世界地图;
+			GAssist::SendKey(hWnd, VK_TAB); SRAND(500, 900);
+			// 等待跑完成;
+			SRAND(600, 800);
+
+			if (i > 10) {
+				DebugLog(_T("未找到镜妖+10"));
+				break;
 			}
+		}
 
-			// 找到镜妖;
+		// 找到镜妖;
+		GAssist::MouseMove(hWnd, CPoint(rc.left + rand() % 10, rc.top + rand() % 10));
+		DebugLog(_T("移动鼠标"));
+		GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3), TRUE);
+		SRAND(300, 600);
+		// 单击目标后,要往移走鼠标,防止下面匹配的时候被鼠标挡住;
+		GAssist::MouseMove(hWnd, CPoint(rc.right + RAND(5, 12), rc.bottom + RAND(5, 10)));
+		SRAND(200, 500);
+		DebugLog(_T("找到目标并单击成功:%s"));
+
+		// 我来抓你;
+		if (GAssist::GetImgMatchtemplate(hWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\我来抓您的.bmp"), rc)) {
+			// 找到匹配的模块;
 			GAssist::MouseMove(hWnd, CPoint(rc.left + rand() % 10, rc.top + rand() % 10));
-			DebugLog(_T("移动鼠标"));
+			DebugLog(_T("我来抓你:移动鼠标"));
 			GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3), TRUE);
-			SRAND(300, 600);
-			// 单击目标后,要往移走鼠标,防止下面匹配的时候被鼠标挡住;
-			GAssist::MouseMove(hWnd, CPoint(rc.right + RAND(5, 12), rc.bottom + RAND(5, 10)));
-			SRAND(200, 500);
-			DebugLog(_T("找到目标并单击成功:%s"));
-
-			// 我来抓你;
-			if (GAssist::GetImgMatchtemplate(hWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\我来抓您的.bmp"), rc)) {
-				// 找到匹配的模块;
-				GAssist::MouseMove(hWnd, CPoint(rc.left + rand() % 10, rc.top + rand() % 10));
-				DebugLog(_T("我来抓你:移动鼠标"));
-				GAssist::MouseClick(hWnd, CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3), TRUE);
-				SRAND(800, 1500);
-				DebugLog(_T("我来抓你:找到目标并单击成功:%s"));
-			}
+			SRAND(800, 1500);
+			DebugLog(_T("我来抓你:找到目标并单击成功:%s"));
 		}
 	}
 }
@@ -953,8 +945,6 @@ void CGameAssistDlg::OnBnClickedButton2()
 
 void CGameAssistDlg::OnBnClickedButton3() // 镜妖;
 {
-	
-#if 1
 	/*
 	-- 是否在星秀村
 	-- 是否在贫民房
@@ -973,6 +963,15 @@ void CGameAssistDlg::OnBnClickedButton3() // 
 	*/
 	CRect rc;
 	HWND hProWnd = GAssist::GetProcessMainWnd();
+	for (int i = 0; i < 100; i++)
+	{
+		UpdateData(FALSE);
+		DebugLog(_T("start.打镜妖 %d----------------------------"), i);
+		BattleJY(hProWnd, m_cbSummoner.GetCheck());
+		DebugLog(_T("end.打镜妖 %d----------------------------\n"), i);
+	}
+
+#if 0
 	if (IsOnMap(hProWnd, _T("img\\地图\\贫民房.bmp")))
 		goto battle;
 
@@ -1022,130 +1021,12 @@ battle:
 		// 找镜妖;
 		for (int i = 0; i < 100; i++)
 		{
+			DebugLog(_T("start.打镜妖 %d----------------------------"), i);
 			BattleJY(hProWnd, m_cbSummoner.GetCheck());
-		}
-	}
-#else
-	// 获取进程句柄;
-	DWORD dwPid = GAssist::GetProcessId();
-	HWND hProWnd = GAssist::GetProMainHwnd(dwPid);
-
-
-	if (GAssist::nGameWndType == GAssist::GW_SMALL)
-	{
-		//// 地图区域;
-		//CRect rc(469,25,635,65);
-		//// 判断当前地图;
-		//if (GAssist::SaveBitmap(GAssist::CopyDC2Bitmap(hProWnd, rc), GAssist::g_strAppdir + _T("Game.bmp")))
-		//{
-		//	if (GAssist::GetImgMatchtemplate(GAssist::g_strAppdir + _T("Game.bmp"), GAssist::g_strAppdir + _T("img\\地图\\应天府.bmp"), rc)) 
-		//	{
-
-		//	}
-		//	else if (GAssist::GetImgMatchtemplate(GAssist::g_strAppdir + _T("Game.bmp"), GAssist::g_strAppdir + _T("img\\地图\\应天府.bmp"), rc))
-		//	{
-
-		//	}
-		//}
-
-		CRect rc;
-		//FIND_NPC(hProWnd, _T("臭美的小米"));
-		Sleep(3000);
-		// 与小米对话;
-		//if (!GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\1-我帮您抓.bmp"), rc)) {
-		//	GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-		//	Sleep(200);
-		//	// 判断是否还有对话,如果没有的话表明不是第一次进入;
-		//	if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\2-我这就去.bmp"), rc)) {
-		//		GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-		//		Sleep(200);
-		//		// 2次对话;
-		//		if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\3-幸运镜妖.bmp"), rc)) {
-		//			GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-		//			Sleep(200);
-		//			// 3次对话;
-		//			if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\3-我就选择它.bmp"), rc)) {
-		//				GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-		//				Sleep(200);
-		//			}
-		//		}
-		//	}
-		//	
-		//	
-		//}
-
-		for (int i = 0; i < 20; i++)
-		{
-			// 进入贫民房;
-			if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\镜妖1.bmp"), rc)) {
-				GAssist::MouseMove(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-				GAssist::MouseMove(hProWnd, CPoint((rc.right + rc.left) / 2 - 1, (rc.top + rc.bottom) / 2 - 1));
-				GAssist::MouseMove(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-				Sleep(200);
-				if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\定位镜妖.bmp"), rc)) {
-					GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-					Sleep(500);
-
-					// 选择我要打你;
-					if (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\活动\\镜妖\\我来抓您的.bmp"), rc)) {
-						GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-						Sleep(500);
-
-						// 判断是否在战斗中;
-						while (GAssist::GetImgMatchtemplate(hProWnd, GAssist::g_strAppdir + _T("img\\头像.bmp"), rc)) {
-							if (rc.left > 60)
-							{
-								GAssist::ShowLog(_T("战斗中"));
-								GAssist::SendKey(hProWnd, 0x41, FALSE, TRUE);
-								Sleep(3000);
-							}
-							else
-							{
-								GAssist::ShowLog(_T("非战斗"));
-								break;
-							}
-						}
-					}
-				}
-			}
-			else {
-				static int i = 0;
-				if (i == 0)
-				{
-					GAssist::SendKey(hProWnd, VK_TAB); Sleep(500);
-					GAssist::MouseClick(hProWnd, CPoint(225, 305));
-					GAssist::SendKey(hProWnd, VK_TAB); Sleep(100);
-					i++;
-				}
-				else if (i == 1)
-				{
-					GAssist::SendKey(hProWnd, VK_TAB); Sleep(500);
-					GAssist::MouseClick(hProWnd, CPoint(300, 266));
-					GAssist::SendKey(hProWnd, VK_TAB); Sleep(100);
-					i++;
-				}
-				else if (i == 2)
-				{
-					GAssist::SendKey(hProWnd, VK_TAB); Sleep(500);
-					GAssist::MouseClick(hProWnd, CPoint(175, 280));
-					GAssist::SendKey(hProWnd, VK_TAB); Sleep(100);
-					i = 0;
-				}
-				Sleep(2000);
-			}
-		}
-
-	}
-	else if (GAssist::nGameWndType == GAssist::GW_LARGE)
-	{
-		CRect rc(630, 25, 800, 65);
-		if (GAssist::SaveBitmap(GAssist::CopyDC2Bitmap(hProWnd, rc), GAssist::g_strAppdir + _T("dt.bmp")))
-		{
-
+			DebugLog(_T("end.打镜妖 %d----------------------------\n"), i);
 		}
 	}
 #endif
-
 }
 
 

BIN
GameAssist/img/活动/镜妖/战斗中.bmp


BIN
GameAssist/img/活动/镜妖/非战斗中.bmp