diff --git a/.gitignore b/.gitignore index a77bc77..81ab2d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vs/ *.cache GenshinBalladsOfBreezeAider/obj/ +GenshinBalladsOfBreezeAider/bin/ diff --git a/GenshinBalladsOfBreezeAider/frmMain.cs b/GenshinBalladsOfBreezeAider/frmMain.cs index dac113f..cf2f69c 100644 --- a/GenshinBalladsOfBreezeAider/frmMain.cs +++ b/GenshinBalladsOfBreezeAider/frmMain.cs @@ -258,20 +258,65 @@ private void Start() bool wHolding = false, sHolding = false, aHolding = false, dHolding = false, iHolding = false, kHolding = false, jHolding = false, lHolding = false; + (double aTailX, double aTailY) = Rotate(376 + 190, 731, 376 , 731, -45); + (double sTailX, double sTailY) = Rotate(573 + 190, 819, 573, 819, -60); + (double dTailX, double dTailY) = Rotate(787 + 190, 870, 787 , 870, -75); + (double jTailX, double jTailY) = Rotate(1133 + 190, 870, 1133, 870, -105); + (double kTailX, double kTailY) = Rotate(1347 + 190, 819, 1347, 819, -120); + (double lTailX, double lTailY) = Rotate(1545 + 190, 731, 1545, 731, -135); + + double aScaleX = 376 / 1920.0; + double sScaleX = 573 / 1920.0; + double dScaleX = 787 / 1920.0; + double jScaleX = 1133 / 1920.0; + double kScaleX = 1347 / 1920.0; + double lScaleX = 1545 / 1920.0; + double aScaleY = 731 / 1080.0; + double sScaleY = 819 / 1080.0; + double dScaleY = 870 / 1080.0; + double jScaleY = 870 / 1080.0; + double kScaleY = 819 / 1080.0; + double lScaleY = 731 / 1080.0; + + double aScaleTailX = aTailX / 1920.0; + double sScaleTailX = sTailX / 1920.0; + double dScaleTailX = dTailX / 1920.0; + double jScaleTailX = jTailX / 1920.0; + double kScaleTailX = kTailX / 1920.0; + double lScaleTailX = lTailX / 1920.0; + + double aScaleTailY = aTailY / 1080.0; + double sScaleTailY = sTailY / 1080.0; + double dScaleTailY = dTailY / 1080.0; + double jScaleTailY = jTailY / 1080.0; + double kScaleTailY = kTailY / 1080.0; + double lScaleTailY = lTailY / 1080.0; + while (working) { Bitmap memoryImage = new Bitmap(width, height); Graphics memoryGraphics = Graphics.FromImage(memoryImage); memoryGraphics.CopyFromScreen(0, 0, 0, 0, new Size(width, height)); - StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.253125, 0.37685, Keys.W, 0.2526, 0.461, ref wHolding); - StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.253125, 0.823148, Keys.S, 0.253125, 0.773, ref sHolding); - StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.127083, 0.6, Keys.A, 0.165625, 0.616, ref aHolding); - StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.378125, 0.6, Keys.D, 0.340625, 0.616, ref dHolding); - StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.74739583, 0.37685, Keys.I, 0.7475, 0.461, ref iHolding); - StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.74739583, 0.823148, Keys.K, 0.7475, 0.773, ref kHolding); - StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.62135416, 0.6, Keys.J, 0.659, 0.616, ref jHolding); - StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.872917, 0.6, Keys.L, 0.835, 0.616, ref lHolding); + #region -- 镜花听世/风物之歌 -- + //StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.253125, 0.37685, Keys.W, 0.2526, 0.461, ref wHolding); + //StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.253125, 0.823148, Keys.S, 0.253125, 0.773, ref sHolding); + //StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.127083, 0.6, Keys.A, 0.165625, 0.616, ref aHolding); + //StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.378125, 0.6, Keys.D, 0.340625, 0.616, ref dHolding); + //StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.74739583, 0.37685, Keys.I, 0.7475, 0.461, ref iHolding); + //StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.74739583, 0.823148, Keys.K, 0.7475, 0.773, ref kHolding); + //StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.62135416, 0.6, Keys.J, 0.659, 0.616, ref jHolding); + //StartAutoPressKeyAndRecordCD(dicKeysNextPressTime, memoryImage, 0.872917, 0.6, Keys.L, 0.835, 0.616, ref lHolding); + #endregion -- 镜花听世/风物之歌 -- + + #region -- 荒 泷 极 上 盛 世 豪 鼓 大 祭 典 -- + StartAutoPressKeyAndRecordCD2(dicKeysNextPressTime, memoryImage, aScaleX, aScaleY , aScaleTailX, aScaleTailY, Keys.A, ref aHolding); + StartAutoPressKeyAndRecordCD2(dicKeysNextPressTime, memoryImage, sScaleX, sScaleY , sScaleTailX, sScaleTailY, Keys.S, ref sHolding); + StartAutoPressKeyAndRecordCD2(dicKeysNextPressTime, memoryImage, dScaleX, dScaleY , dScaleTailX, dScaleTailY, Keys.D, ref dHolding); + StartAutoPressKeyAndRecordCD2(dicKeysNextPressTime, memoryImage, jScaleX, jScaleY , jScaleTailX, jScaleTailY, Keys.J, ref jHolding); + StartAutoPressKeyAndRecordCD2(dicKeysNextPressTime, memoryImage, kScaleX, kScaleY , kScaleTailX, kScaleTailY, Keys.K, ref kHolding); + StartAutoPressKeyAndRecordCD2(dicKeysNextPressTime, memoryImage, lScaleX, lScaleY , lScaleTailX, lScaleTailY, Keys.L, ref lHolding); + #endregion -- 荒 泷 极 上 盛 世 豪 鼓 大 祭 典 -- memoryGraphics.Dispose(); memoryImage.Dispose(); @@ -281,6 +326,7 @@ private void Start() private void btnDebugScreenshot_Click(object sender, EventArgs e) => SaveDebugImage(); + [Obsolete] private void StartAutoPressKeyAndRecordCD(Dictionary dicKeysNextPressTime, Bitmap bmp, double scaleX, double scaleY, Keys key, double scaleHoldX, double scaleHoldY, ref bool holding) { if (dicKeysNextPressTime.ContainsKey(key)) @@ -292,8 +338,26 @@ private void StartAutoPressKeyAndRecordCD(Dictionary dicKeysNext dicKeysNextPressTime.Add(key, StartAutoPressKey(bmp, scaleX, scaleY, key, scaleHoldX, scaleHoldY, ref holding)); } + private void StartAutoPressKeyAndRecordCD2(Dictionary dicKeysNextPressTime, Bitmap bmp, double scaleX, double scaleY, double scaleTailX, double scaleTailY, Keys key, ref bool holding) + { + if (dicKeysNextPressTime.ContainsKey(key)) + { + if (dicKeysNextPressTime[key] < DateTime.Now) + dicKeysNextPressTime[key] = StartAutoPressKey2(bmp, scaleX, scaleY, scaleTailX, scaleTailY, key, ref holding); + } + else + dicKeysNextPressTime.Add(key, StartAutoPressKey2(bmp, scaleX, scaleY, scaleTailX, scaleTailY, key, ref holding)); + } + + private (double x, double y) Rotate(double targetX, double targetY, double centerX, double centerY, double angle) + { + double x = (targetX - centerX) * Math.Cos(Math.PI / 180.0 * angle) - (targetY - centerY) * Math.Sin(Math.PI / 180.0 * angle) + centerX; + double y = (targetX - centerX) * Math.Sin(Math.PI / 180.0 * angle) + (targetY - centerY) * Math.Cos(Math.PI / 180.0 * angle) + centerY; + return (x, y); + } + private int debugIndex = 1; - private void SaveDebugImage(Keys onlyDrawKey = Keys.None, string debugText = "") + private void SaveDebugImage() { int width = (int)Math.Round(Screen.PrimaryScreen.Bounds.Width * DpiScaleX); int height = (int)Math.Round(Screen.PrimaryScreen.Bounds.Height * DpiScaleY); @@ -302,6 +366,7 @@ private void SaveDebugImage(Keys onlyDrawKey = Keys.None, string debugText = "") Graphics memoryGraphics = Graphics.FromImage(memoryImage); memoryGraphics.CopyFromScreen(0, 0, 0, 0, size); + #region -- 镜花听世/风物之歌 -- #region -- 点按判定位置 -- //DrawDebugLine(0.253125, 0.37685, memoryImage, Keys.W); //DrawDebugLine(0.253125, 0.823148, memoryImage, Keys.S); @@ -323,13 +388,35 @@ private void SaveDebugImage(Keys onlyDrawKey = Keys.None, string debugText = "") //DrawDebugLine(0.7475, 0.773 - 0.15, memoryImage, Keys.K); //DrawDebugLine(0.835, 0.616 - 0.15, memoryImage, Keys.L); #endregion -- 长按判定位置 -- + #endregion -- 镜花听世/风物之歌 -- + + #region -- 荒 泷 极 上 盛 世 豪 鼓 大 祭 典 -- + DrawDebugLine(376 / 1920.0, 731 / 1080.0, memoryImage, Keys.A); + DrawDebugLine(573 / 1920.0, 819 / 1080.0, memoryImage, Keys.S); + DrawDebugLine(787 / 1920.0, 870 / 1080.0, memoryImage, Keys.D); + DrawDebugLine(1133 / 1920.0, 870 / 1080.0, memoryImage, Keys.J); + DrawDebugLine(1347 / 1920.0, 819 / 1080.0, memoryImage, Keys.K); + DrawDebugLine(1545 / 1920.0, 731 / 1080.0, memoryImage, Keys.L); + + //(double aX, double aY) = Rotate(376 + 190, 731, 376, 731, -45); + //(double sX, double sY) = Rotate(573 + 190, 819, 573, 819, -60); + //(double dX, double dY) = Rotate(787 + 190, 870, 787, 870, -75); + //(double jX, double jY) = Rotate(1133 + 190, 870, 1133, 870, -105); + //(double kX, double kY) = Rotate(1347 + 190, 819, 1347, 819, -120); + //(double lX, double lY) = Rotate(1545 + 190, 731, 1545, 731, -135); + + //DrawDebugLine(aX / 1920.0, aY / 1080.0, memoryImage, Keys.A); + //DrawDebugLine(sX / 1920.0, sY / 1080.0, memoryImage, Keys.S); + //DrawDebugLine(dX / 1920.0, dY / 1080.0, memoryImage, Keys.D); + //DrawDebugLine(jX / 1920.0, jY / 1080.0, memoryImage, Keys.J); + //DrawDebugLine(kX / 1920.0, kY / 1080.0, memoryImage, Keys.K); + //DrawDebugLine(lX / 1920.0, lY / 1080.0, memoryImage, Keys.L); + #endregion -- 荒 泷 极 上 盛 世 豪 鼓 大 祭 典 -- memoryImage.Save(Application.StartupPath + @$"\Screenshot{debugIndex++}.jpg"); void DrawDebugLine(double scaleX, double scaleY, Bitmap highDpiScreenshot, Keys key) { - if (onlyDrawKey != Keys.None && onlyDrawKey != key) - return; int xw = (int)Math.Round(genshinWindowWdith * scaleX) + genshinWindowX; int yw = (int)Math.Round(genshinWindowHeight * scaleY) + genshinWindowY; for (int i = xw - 25; i < xw + 25; i++) @@ -337,11 +424,12 @@ void DrawDebugLine(double scaleX, double scaleY, Bitmap highDpiScreenshot, Keys for (int i = yw - 25; i < yw + 25; i++) highDpiScreenshot.SetPixel(xw, i, Color.Red); Graphics g = Graphics.FromImage(highDpiScreenshot); - g.DrawString(debugText, new Font("宋体", 12), Brushes.Red, xw, yw); + g.DrawString(key.ToString(), new Font("宋体", 12), Brushes.Red, xw, yw); g.Dispose(); } } + [Obsolete] private DateTime StartAutoPressKey(Bitmap bmp, double scaleX, double scaleY, Keys key, double scaleHoldX, double scaleHoldY, ref bool holding) { byte byteKey = (byte)key; @@ -374,7 +462,7 @@ private DateTime StartAutoPressKey(Bitmap bmp, double scaleX, double scaleY, Key holding = false; if (debugTextBox.Visible) BeginInvoke(new Action(() => debugTextBox.AppendText($"弹起按键:{key} ----{DateTime.Now}\r\n"))); - //SaveDebugImage(key, $"弹起{key}({colorHold.R},{colorHold.G},{colorHold.B})"); + //SaveDebugImage()"); return DateTime.Now; } } @@ -391,7 +479,7 @@ private DateTime StartAutoPressKey(Bitmap bmp, double scaleX, double scaleY, Key if (debugTextBox.Visible) BeginInvoke(new Action(() => debugTextBox.AppendText($"点按按键{key}----{DateTime.Now}\r\n"))); Task.Delay(50).ContinueWith(_ => keybd_event(byteKey, code, 2, 0)); - //SaveDebugImage(key, $"点按{key}({color.R},{color.G},{color.B})"); + //SaveDebugImage(); return DateTime.Now.AddMilliseconds(200); } @@ -410,11 +498,74 @@ private DateTime StartAutoPressKey(Bitmap bmp, double scaleX, double scaleY, Key if (debugTextBox.Visible) BeginInvoke(new Action(() => debugTextBox.AppendText($"按住按键:{key} ----{DateTime.Now}\r\n"))); - //SaveDebugImage(key, $"长按{key}({colorHold.R},{colorHold.G},{colorHold.B}),({colorTail.R},{colorTail.G},{colorTail.B})"); + //SaveDebugImage(); return DateTime.Now.AddMilliseconds(500); } } return DateTime.Now; } + + + private DateTime StartAutoPressKey2(Bitmap bmp, double scaleX, double scaleY, double scaleTailX, double scaleTailY, Keys key, ref bool holding) + { + byte byteKey = (byte)key; + byte code = key switch + { + Keys.W => Convert.ToByte(0x11), + Keys.S => Convert.ToByte(0x1F), + Keys.A => Convert.ToByte(0x1E), + Keys.D => Convert.ToByte(0x20), + Keys.I => Convert.ToByte(0x17), + Keys.K => Convert.ToByte(0x25), + Keys.J => Convert.ToByte(0x24), + Keys.L => Convert.ToByte(0x26), + _ => throw new Exception() + }; + + //点按 + int x = (int)Math.Round(genshinWindowWdith * scaleX) + genshinWindowX; + int y = (int)Math.Round(genshinWindowHeight * scaleY) + genshinWindowY; + + Color color = bmp.GetPixel(x, y); + //if (holding) + //{ + // //弹起 + // int xTail = (int)Math.Round(genshinWindowWdith * scaleTailX) + genshinWindowX; + // int yTail = (int)Math.Round(genshinWindowHeight * scaleTailY) + genshinWindowY; + // Color colorTail = bmp.GetPixel(xTail, yTail); + // if (colorTail.B > 245) + // { + // Task.Run(() => keybd_event(byteKey, code, 2, 0)); + // holding = false; + // if (debugTextBox.Visible) + // BeginInvoke(new Action(() => debugTextBox.AppendText($"弹起按键:{key} ----{DateTime.Now}\r\n"))); + // //SaveDebugImage(); + // return DateTime.Now.AddMilliseconds(100); + // } + //} + //else + //if (color.R > 160 && color.G < 190 && color.B > 220) + //{ + // keybd_event(byteKey, code, 2, 0); + // Task.Run(() => keybd_event(byteKey, code, 1, 0)); + // holding = true; + + // if (debugTextBox.Visible) + // BeginInvoke(new Action(() => debugTextBox.AppendText($"按住按键:{key} ----{DateTime.Now}\r\n"))); + // //SaveDebugImage(); + // return DateTime.Now.AddMilliseconds(200); + //} + //else + if (color.B < 160) + { + keybd_event(byteKey, code, 0, 0); + if (debugTextBox.Visible) + BeginInvoke(new Action(() => debugTextBox.AppendText($"点按按键{key}----{DateTime.Now}\r\n"))); + Task.Delay(20).ContinueWith(_ => keybd_event(byteKey, code, 2, 0)); + //SaveDebugImage(); + return DateTime.Now.AddMilliseconds(100); + } + return DateTime.Now; + } } } diff --git a/GenshinBalladsOfBreezeAider/obj/Debug/GenshinBalladsOfBreezeAider.csproj.FileListAbsolute.txt b/GenshinBalladsOfBreezeAider/obj/Debug/GenshinBalladsOfBreezeAider.csproj.FileListAbsolute.txt deleted file mode 100644 index e69de29..0000000