Explorar o código

将打印函数放入全局命名中

Jeff %!s(int64=3) %!d(string=hai) anos
pai
achega
15b7e033bb

+ 14 - 1
GameAssist/GameAssist/Assist.cpp

@@ -630,6 +630,19 @@ namespace GameGlobal
 
 		return std::string(szName);
 	}
+
+	VOID DebugLog(CHAR* pszStr, ...)
+	{
+		char szData[MAX_PATH] = { 0 };
+		_stprintf_s(szData, _T("%s %s "), _T("[GameAssist] "), CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S")).GetString());
+		int len = strlen(szData);
+		va_list args;
+		va_start(args, pszStr);
+		_vsnprintf_s(szData + len, MAX_PATH - len, MAX_PATH - len, pszStr, args);
+		va_end(args);
+		strcat_s(szData, "\n");
+		OutputDebugStringA(szData);
+	}
 };
 
 namespace ImgAssist
@@ -971,7 +984,7 @@ namespace ImgAssist
 		}
 		src.release();
 
-		TRACE3("[GameAssist] ÑÕɫռ±È=%d,%d,%d\n", i, width, i * 100 / width);
+		GameGlobal::DebugLog(_T("[GameAssist] ÑÕɫռ±È=%d,%d,%d"), i, width, i * 100 / width);
 
 		return i * 100 / width ;
 	}

+ 1 - 0
GameAssist/GameAssist/Assist.h

@@ -30,6 +30,7 @@ namespace GameGlobal {
 
 	void Init();
 	std::string BuildImgPath(HWND hWnd, LPCTSTR lpName = NULL);
+	VOID DebugLog(CHAR* pszStr, ...);
 };
 
 namespace ImgAssist {

+ 21 - 34
GameAssist/GameAssist/CAction.cpp

@@ -41,19 +41,6 @@ SRAND(80,120);
 
 
 	ThreadSection CAction::m_ts;
-	VOID DebugLog(CHAR* pszStr, ...)
-	{
-		char szData[MAX_PATH] = { 0 };
-		_stprintf_s(szData, _T("%s %s "), _T("[GameAssist] "), CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S")).GetString());
-		int len = strlen(szData);
-		va_list args;
-		va_start(args, pszStr);
-		_vsnprintf_s(szData + len, MAX_PATH - len, MAX_PATH - len, pszStr, args);
-		va_end(args);
-		strcat_s(szData, "\n");
-		OutputDebugStringA(szData);
-	}
-
 	CAction::CAction(HWND hWnd) :m_hGameWnd(hWnd), m_ptCur({ 0,0 })
 	{
 		m_hBattleJY = NULL;
@@ -230,7 +217,7 @@ SRAND(80,120);
 			// 判断2张图片是否一样;
 			if (ImgAssist::IsSimilarPicture(strImg.c_str(), strImg2.c_str()))
 			{
-				DebugLog(_T("停止走路"));
+				GameGlobal::DebugLog(_T("停止走路"));
 				return true;
 			}
 		}
@@ -243,11 +230,11 @@ SRAND(80,120);
 		CRect rc;
 		SRAND(100, 200);
 		if (ImgAssist::IsMatchIcon(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\活动\\镜妖\\非战斗中.bmp"), { 630, 25, 805, 45 }, rc)) {
-			DebugLog(_T("Battle:非战斗中"));
+			GameGlobal::DebugLog(_T("Battle:非战斗中"));
 			return false;
 		}
 
-		DebugLog(_T("Battle:战斗中"));
+		GameGlobal::DebugLog(_T("Battle:战斗中"));
 		return true;
 	}
 
@@ -256,17 +243,17 @@ SRAND(80,120);
 		CRect rc;
 		TCHAR szTemplateImage[MAX_PATH] = { 0 };
 		// 先截图;
-		DebugLog(_T("FindMatchIcon=%s"), lpszTemplateImage);
+		GameGlobal::DebugLog(_T("FindMatchIcon=%s"), lpszTemplateImage);
 		ImgAssist::CaptureGameWnd(m_hGameWnd); SRAND(200, 500);
 		_stprintf_s(szTemplateImage, _T("%s%s"), GameGlobal::g_strAppdir.c_str(), lpszTemplateImage);
 		if (ImgAssist::GetImgMatchtemplate(GameGlobal::BuildImgPath(m_hGameWnd), szTemplateImage, rc)) {
 			// 找到匹配的模块;
-			DebugLog(_T("====> 找到匹配目标:%s"), lpszTemplateImage);
+			GameGlobal::DebugLog(_T("====> 找到匹配目标:%s"), lpszTemplateImage);
 			return rc;
 		}
 
 		rc.SetRectEmpty();
-		DebugLog(_T("<==== 没找到匹配目标:%s"), lpszTemplateImage);
+		GameGlobal::DebugLog(_T("<==== 没找到匹配目标:%s"), lpszTemplateImage);
 		return rc;
 	}
 
@@ -304,7 +291,7 @@ SRAND(80,120);
 		CRect rc;
 		BOOL bIsAttack = FALSE;
 		if (ImgAssist::IsMatchIcon(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\我方攻击2.bmp"), { 720, 85, 806, 120 }, rc)) {
-			DebugLog(_T("IsWattingAttack:我方攻击中……"));
+			GameGlobal::DebugLog(_T("IsWattingAttack:我方攻击中……"));
 			bIsAttack = TRUE;
 		}
 
@@ -527,11 +514,11 @@ SRAND(80,120);
 		while (IsFighting()) {
 			// 2.是否我方攻击;
 			while (IsWattingAttack(0)) { // Bug:如果被镜妖打死了,无法中断;
-				DebugLog(_T("BattleJY:我方攻击……"));
+				GameGlobal::DebugLog(_T("BattleJY:我方攻击……"));
 				if (bFirstAttack)
 				{
 					SRAND(350, 500);	// 有时切换需要时间,如果不延时会失败;
-					DebugLog(_T("BattleJY:第一次攻击……"));
+					GameGlobal::DebugLog(_T("BattleJY:第一次攻击……"));
 					// 根据角色选择技能;
 					SendKey(VK_F1);
 					SRAND(300, 350);
@@ -545,13 +532,13 @@ SRAND(80,120);
 					if (bHasSummoner) {
 						CRect rc;
 						// 召唤兽技能;
-						DebugLog(_T("BattleJY:召唤兽技能选择"));
+						GameGlobal::DebugLog(_T("BattleJY:召唤兽技能选择"));
 
 						// 选择重击;
 						if (nZJType) {
 							SRAND(150, 350);
 							SendKey(VK_S, FALSE, TRUE);
-							DebugLog(_T("BattleJY:召唤兽技能选择:%d"), nZJType);
+							GameGlobal::DebugLog(_T("BattleJY:召唤兽技能选择:%d"), nZJType);
 							if (ImgAssist::GetImgMatchtemplate(m_hGameWnd, nZJType == 1 ? GameGlobal::g_strAppdir + _T("img\\活动\\镜妖\\重击.bmp") : GameGlobal::g_strAppdir + _T("img\\活动\\镜妖\\重击2.bmp"), rc))
 							{
 								SRAND(150, 300);
@@ -568,7 +555,7 @@ SRAND(80,120);
 				}
 				else
 				{
-					DebugLog(_T("BattleJY:不是第一次攻击……"));
+					GameGlobal::DebugLog(_T("BattleJY:不是第一次攻击……"));
 					SendKey(VK_A, FALSE, TRUE);
 					SRAND(80, 100);
 					if (bFirstAttack) {
@@ -642,30 +629,30 @@ SRAND(80,120);
 				// 移动下鼠标;
 				MouseMove(spt[(i+1)%4]);
 				if (i > 10) {
-					DebugLog(_T("未找到镜妖+10"));
+					GameGlobal::DebugLog(_T("未找到镜妖+10"));
 					break;
 				}
 			}
 
 			// 找到镜妖;
 			MouseMove(CPoint(rc.left + rand() % 10, rc.top + rand() % 10));
-			DebugLog(_T("移动鼠标"));
+			GameGlobal::DebugLog(_T("移动鼠标"));
 			MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3));
 			SRAND(390, 600);
 			// 单击目标后,要往移走鼠标,防止下面匹配的时候被鼠标挡住;
 			MouseMove(CPoint(rc.right + RAND(10, 20), rc.bottom + RAND(10, 20)));
 			SRAND(300, 500);
-			DebugLog(_T("找到目标并单击成功:%s"));
+			GameGlobal::DebugLog(_T("找到目标并单击成功:%s"));
 
 			// 我来抓你;
 			if (ImgAssist::GetImgMatchtemplate(m_hGameWnd, GameGlobal::g_strAppdir + _T("img\\活动\\镜妖\\我来抓您的.bmp"), rc)) {
 				// 找到匹配的模块;
 				SRAND(200, 300);
 				//MouseMove(hWnd, CPoint(rc.left + rand() % 10, rc.top + rand() % 10));
-				DebugLog(_T("我来抓你:移动鼠标"));
+				GameGlobal::DebugLog(_T("我来抓你:移动鼠标"));
 				MouseClick(CPoint((rc.right + rc.left) / 2 + rand() % 3, (rc.top + rc.bottom) / 2 + rand() % 3));
 				SRAND(1000, 1500);
-				DebugLog(_T("我来抓你:找到目标并单击成功:%s"));
+				GameGlobal::DebugLog(_T("我来抓你:找到目标并单击成功:%s"));
 			}
 		}
 	}
@@ -695,7 +682,7 @@ SRAND(80,120);
 			if (!rc.IsRectEmpty() && !rc.IsRectNull())
 			{
 				// 只有离开这里:已经打过,右键并退出 ;
-				DebugLog("只有离开这里:已经打过,右键并退出");
+				GameGlobal::DebugLog("只有离开这里:已经打过,右键并退出");
 				MouseRClick({rc.left, rc.top});
 				SRAND(200, 500);
 				return;
@@ -794,7 +781,7 @@ SRAND(80,120);
 			// 人物:Alt+S显示技能,双击选择技能,单击怪物发动技能;
 			// 注:有的人物技能太多,导致会有滚动条:这是有难点;
 			BOOL bRet = FindJNShortCut(lpszSkillName, KeyValue, SkillTime);
-			DebugLog("快捷键值=%ld", KeyValue);
+			GameGlobal::DebugLog("快捷键值=%ld", KeyValue);
 
 			// 快捷键;
 			SendKey(KeyValue);
@@ -1153,9 +1140,9 @@ SRAND(80,120);
 		CAction* pThis = (CAction*)lpParam;
 		do 
 		{
-			DebugLog(_T("start.打镜妖 %d----------------------------"), i);
+			GameGlobal::DebugLog(_T("start.打镜妖 %d----------------------------"), i);
 			pThis->FightingJY(pThis->m_bHasSummoner, pThis->m_nSummonerSkillType, pThis->m_bTargetOfRoleSkill);
-			DebugLog(_T("end.打镜妖 %d----------------------------\n"), i++);
+			GameGlobal::DebugLog(_T("end.打镜妖 %d----------------------------\n"), i++);
 		} while (WaitForSingleObject(pThis->m_hBattleJYEvent, 200) == WAIT_TIMEOUT);
 
 		return 0;