Bladeren bron

开宝箱函数

Wang Jeff 4 jaren geleden
bovenliggende
commit
7300bbaccc
1 gewijzigde bestanden met toevoegingen van 50 en 45 verwijderingen
  1. 50 45
      GameAssist/GameAssist/GameAssistDlg.cpp

+ 50 - 45
GameAssist/GameAssist/GameAssistDlg.cpp

@@ -27,10 +27,10 @@ class CAboutDlg : public CDialog
 public:
 	CAboutDlg();
 
-// 对话框数据
+	// 对话框数据
 	enum { IDD = IDD_ABOUTBOX };
 
-	protected:
+protected:
 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
 
 // 实现
@@ -173,11 +173,11 @@ void CGameAssistDlg::OnBnClickedOpengame()
 	DWORD dwPid = GAssist::GetProcessId();
 	HWND hProWnd = GAssist::GetProMainHwnd(dwPid);
 	//HWND hProWnd = GAssist::GetProMainHwnd(5824);
-	TCHAR szWinText[MAX_PATH] = {0};
+	TCHAR szWinText[MAX_PATH] = { 0 };
 	::GetWindowText(hProWnd, szWinText, MAX_PATH);
 
 #if 1
- 	Sleep(1000);
+	Sleep(1000);
 	m_mouseAssist.BindWnd(hProWnd, PT_TYPE::WINDOW_POINT);
 	m_mouseAssist.MoveTo(205, 150);
 	Sleep(1000);
@@ -189,10 +189,10 @@ void CGameAssistDlg::OnBnClickedOpengame()
 	m_mouseAssist.MoveTo(10, 470);
 	m_mouseAssist.LeftClick();
 	/*GAssist::MouseMove(hProWnd, CPoint(205,150));
- 	Sleep(2000);
- 	GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(250,250));
- 	Sleep(2000);
- 	GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(350,350));*/
+	Sleep(2000);
+	GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(250,250));
+	Sleep(2000);
+	GAssist::MouseMove(hProWnd, CPoint(100,100), CPoint(350,350));*/
 
 	return;
 #endif
@@ -200,23 +200,23 @@ void CGameAssistDlg::OnBnClickedOpengame()
 	if (0)
 	{
 		Sleep(1000);
-		GAssist::MouseClick(hProWnd, CPoint(205,150));
+		GAssist::MouseClick(hProWnd, CPoint(205, 150));
 
 		Sleep(1000);
-		GAssist::MouseClick(hProWnd, CPoint(235,150));
+		GAssist::MouseClick(hProWnd, CPoint(235, 150));
 
 		Sleep(1000);
-		GAssist::MouseClick(hProWnd, CPoint(275,150));
+		GAssist::MouseClick(hProWnd, CPoint(275, 150));
 	}
 
 	if (0)
 	{
 		Sleep(1000);
 		::SetForegroundWindow(hProWnd);
-		GAssist::DragMouse(hProWnd, CPoint(173,192), CPoint(295,190));
+		GAssist::DragMouse(hProWnd, CPoint(173, 192), CPoint(295, 190));
 	}
 
-	if (0){
+	if (0) {
 		GAssist::MouseDbClick(hProWnd, CPoint(476, 158));
 	}
 
@@ -225,7 +225,7 @@ void CGameAssistDlg::OnBnClickedOpengame()
 		GAssist::SendKey(hProWnd, VK_TAB);
 	}
 
-	if ( 1 )
+	if (1)
 	{// 小窗口-职业挑战;
 		//// 打开世界地图;
 		//GAssist::SendKey(hProWnd, VK_TAB);Sleep(300);
@@ -248,11 +248,11 @@ void CGameAssistDlg::OnBnClickedOpengame()
 		RECT rc;
 		BOOL bMatch = FALSE;
 		int trySize = 20;
-		while ( !(bMatch = GAssist::GetImgMatchtemplate(GAssist::g_strAppdir + _T("Game.bmp"), GAssist::g_strAppdir + _T("img\\zyxdds-wytztm.bmp"), rc)) ) {
+		while (!(bMatch = GAssist::GetImgMatchtemplate(GAssist::g_strAppdir + _T("Game.bmp"), GAssist::g_strAppdir + _T("img\\zyxdds-wytztm.bmp"), rc))) {
 			Sleep(3000);
 			// 截图;
 			GAssist::SaveHwndToBmpFile(hProWnd, GAssist::g_strAppdir + _T("Game.bmp"));
-			if ( !trySize-- ) break;
+			if (!trySize--) break;
 		}
 
 		if (bMatch) {
@@ -260,7 +260,7 @@ void CGameAssistDlg::OnBnClickedOpengame()
 			TRACE2("坐标2 x=%d,y=%d\n", (rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2);
 			GAssist::MouseMove(hProWnd, CPoint(rc.left, rc.top));
 			// 单击:我要挑战他们;
-			GAssist::MouseClick(hProWnd, CPoint((rc.right+rc.left)/2, (rc.top+rc.bottom)/2), TRUE);
+			GAssist::MouseClick(hProWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2), TRUE);
 			Sleep(2300);// 等出图;
 
 			// 再单击:我准备好了;
@@ -290,7 +290,7 @@ void CGameAssistDlg::OnBnClickedOpengame()
 				}
 			}
 		}
-		
+
 	}
 
 	//RECT rc = {0,0,500,500};
@@ -301,7 +301,7 @@ void CGameAssistDlg::OnBnClickedOpengame()
 #endif
 
 	// TODO: 在此添加控件通知处理程序代码
-	if ( !PathFileExists(GAssist::g_szGameApp) )
+	if (!PathFileExists(GAssist::g_szGameApp))
 	{
 		MessageBox("游戏程序不存在", "温馨提示");
 		return;
@@ -327,15 +327,15 @@ void CGameAssistDlg::OnBnClickedOpengame()
 	{
 		DWORD dwError = GetLastError();
 		CString strError = _T("");
-		strError.Format(_T("执行ShellExecuteEx失败,错误码:%d"),dwError);
+		strError.Format(_T("执行ShellExecuteEx失败,错误码:%d"), dwError);
 		AfxMessageBox(strError);
-		return ;
+		return;
 	}
 
 	HANDLE hProcess = stuExecInfo.hProcess;
-	if ( hProcess != NULL )
+	if (hProcess != NULL)
 	{
-		WaitForSingleObject(hProcess,INFINITE);
+		WaitForSingleObject(hProcess, INFINITE);
 		CloseHandle(hProcess);
 	}
 
@@ -345,57 +345,57 @@ void CGameAssistDlg::OnBnClickedOpengame()
 #if 1
 	EnumWindows(GAssist::EnumChildWindowCallBack, dwPID);
 
-	if ( GAssist::g_vtGameHwnd.size() )
+	if (GAssist::g_vtGameHwnd.size())
 	{
 		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 ( _tcsicmp(it->strWinText.c_str(), _T("最小化")) == 0 )
+			if (_tcsicmp(it->strWinText.c_str(), _T("最小化")) == 0)
 			{
 				gbmin = &*it;
 			}
 
-			if ( _tcsicmp(it->strWinText.c_str(), _T("大话水浒")) == 0 )
+			if (_tcsicmp(it->strWinText.c_str(), _T("大话水浒")) == 0)
 			{
 				gp = &*it;
 			}
 
-			if ( _tcsicmp(it->strWinText.c_str(), _T("进入游戏")) == 0 )
+			if (_tcsicmp(it->strWinText.c_str(), _T("进入游戏")) == 0)
 			{
 				gbentry = &*it;
 			}
 		}
 
-		if ( gp && gbentry && gbmin)
+		if (gp && gbentry && gbmin)
 		{
 			//::SendMessage(gp->hwnd, WM_LBUTTONDOWN, (WPARAM)gb->dwId, 0);
 			//::SendMessage(gp->hwnd, WM_LBUTTONUP, (WPARAM)gb->dwId, 0);
 			// 发送点击事件;
 			// 先最小化;
-			::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);
 
 
 			Sleep(1500);
 			dwPID = GAssist::GetProcessId();
-			if ( dwPID )
+			if (dwPID)
 			{
 				GAssist::g_vtGameHwnd.clear();
 				EnumWindows(GAssist::EnumChildWindowCallBack, dwPID);
 				HWND hwnd = GAssist::GetProMainHwnd(dwPID);
-				if ( hwnd )
+				if (hwnd)
 				{
-					TCHAR szName[MAX_PATH] = {0};
+					TCHAR szName[MAX_PATH] = { 0 };
 					::GetWindowText(hwnd, szName, MAX_PATH);
 					CRect rc;
 					::GetWindowRect(hwnd, &rc);
-					TCHAR szLogMsg[MAX_PATH] = {0};
+					TCHAR szLogMsg[MAX_PATH] = { 0 };
 					_stprintf_s(szLogMsg, _T("窗口标题:%s, [%d,%d, %d,%d], width=%d, height=%d\n"), szName, rc.top, rc.left, rc.right, rc.bottom, rc.Width(), rc.Height());
 					OutputDebugString(szLogMsg);
-					if ( 1 )
+					if (1)
 					{ // 800x600
 						// 发送按钮消息;进入游戏;
 						GAssist::MouseClick(hwnd, 585, 116);
@@ -433,7 +433,7 @@ void CGameAssistDlg::OnBnClickedOpengame()
 void CGameAssistDlg::OnBnClickedButton2()
 {
 	// TODO: 在此添加控件通知处理程序代码
-	
+
 // 	VideoDXGICaptor vdx;
 // 	if (vdx.Init())
 // 	{
@@ -455,8 +455,8 @@ void CGameAssistDlg::OnBnClickedButton3()
 	DWORD dwPid = GAssist::GetProcessId();
 	HWND hProWnd = GAssist::GetProMainHwnd(dwPid);
 
-	
-	if ( GAssist::nGameWndType == GAssist::GW_SMALL )
+
+	if (GAssist::nGameWndType == GAssist::GW_SMALL)
 	{
 		//// 地图区域;
 		//CRect rc(469,25,635,65);
@@ -587,26 +587,31 @@ void CGameAssistDlg::OnBnClickedButton5()
 		CRect rc;
 		MouseAssist mouseAssist;
 		mouseAssist.BindWnd(hProcessMainWnd, PT_TYPE::SCREEN_POINT);
-		for (int i = 0; i < 2; i++)
+		for (int i = 0; i < 50; i++)
 		{
 			if (!GAssist::GetImgMatchtemplate(hProcessMainWnd, GAssist::g_strAppdir + _T("img\\开宝箱\\应天府铁匠.bmp"), rc))
 			{
-				// 在当前位置右键一次;
-				GAssist::MouseDbClick(hProcessMainWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
+				mouseAssist.GetCursorPos();
+				mouseAssist.MoveTo(rc.top - rand() % 10, rc.left - rand() % 10);
+				mouseAssist.RightClick();
 			}
 			else
 			{
 				GAssist::MouseClick(hProcessMainWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-				Sleep(500);
+				Sleep(600);
 				// 判断是否还有对话,如果没有的话表明不是第一次进入;
 				if (GAssist::GetImgMatchtemplate(hProcessMainWnd, GAssist::g_strAppdir + _T("img\\开宝箱\\开宝箱.bmp"), rc)) {
 
 					GAssist::MouseDbClick(hProcessMainWnd, CPoint((rc.right + rc.left) / 2, (rc.top + rc.bottom) / 2));
-					Sleep(200);
+					Sleep(rand() % 200 + 190);
+					// 然后移动出去;
+					//GAssist::MouseMove(hProcessMainWnd, CPoint(rc.top - 50 - rand()%20, rc.left - 50 - rand() % 20));
+					mouseAssist.GetCursorPos();
+					mouseAssist.MoveToEx(rc.top, rc.left, rc.Width(), rc.Height());
 				}
 			}
 
-			Sleep(200);
+			Sleep(600 + rand() % 300);
 		}
 	}