From d0b8f4fd16831ac4608be5d0a2ba76191d6a5d1c Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 28 Sep 2019 15:15:12 +0300 Subject: [PATCH 1/2] - attempt #1 --- .../ApLegWeaponTypeScreenRecognizer.cs | 1 + .../ScreenCapture.cs | 38 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ScreenAssistant.ScreenInfoRecognition/Recognizers/ApexLegends/ApLegWeaponTypeScreenRecognizer.cs b/ScreenAssistant.ScreenInfoRecognition/Recognizers/ApexLegends/ApLegWeaponTypeScreenRecognizer.cs index fdb160a..b5f9842 100644 --- a/ScreenAssistant.ScreenInfoRecognition/Recognizers/ApexLegends/ApLegWeaponTypeScreenRecognizer.cs +++ b/ScreenAssistant.ScreenInfoRecognition/Recognizers/ApexLegends/ApLegWeaponTypeScreenRecognizer.cs @@ -77,6 +77,7 @@ private static DirectBitmap GetAdjustedDirectBitmapOfImage(Image img, float brig public string TestWeapons() { + this._logger?.NewSnapshot(); var w1Img = GetWeapon1Image(FullScreenMode); var w2Img = GetWeapon2Image(FullScreenMode); w1Img.SaveTestImage(); diff --git a/ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs b/ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs index 84c04b8..376c200 100644 --- a/ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs +++ b/ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using System.Drawing.Imaging; +using System.IO; using System.Runtime.InteropServices; namespace TiqSoft.ScreenAssistant.ScreenInfoRecognition @@ -29,7 +30,7 @@ public static Image CaptureScreenRelatively(float startX, float endX, float star { if (fullScreen) { - return CaptureWindow(User32.GetDesktopWindow(), startX, endX, startY, endY); + return CaptureWindowFromGraphics(User32.GetForegroundWindow(), startX, endX, startY, endY); } return CaptureWindow(User32.GetForegroundWindow(), startX, endX, startY, endY); @@ -74,6 +75,41 @@ internal static Image CaptureWindow(IntPtr handle, float startX, float endX, flo GDI32.DeleteObject(hBitmap); return img; } + + /// + /// Creates an Image object containing a screen shot of a specific window + /// + /// The handle to the window. + /// 0-100 percent of start by X + /// 0-100 percent of end by X + /// 0-100 percent of start by Y + /// 0-100 percent of end by Y + /// + internal static Image CaptureWindowFromGraphics(IntPtr handlePtr, float startX, float endX, float startY, float endY) + { + User32.RECT windowRect = new User32.RECT(); + User32.GetWindowRect(handlePtr, ref windowRect); + int width = windowRect.right - windowRect.left; + int height = windowRect.bottom - windowRect.top; + var tWidth = (int) ((endX - startX) * width / 100); + var tHeight = (int) ((endY - startY) * height / 100); + var xSrc = (int) (startX * width / 100); + var ySrc = (int) (startY * height / 100); + + if (tWidth > 0 && tHeight > 0) + { + Bitmap bitmap = new Bitmap(tWidth, tHeight); + using (Graphics g = Graphics.FromImage(bitmap)) + { + g.CopyFromScreen(new Point(xSrc, ySrc), Point.Empty, new Size(tWidth, tHeight)); + } + return bitmap; + } + + return new Bitmap(1, 1); + } + + /// /// Captures a screen shot of a specific window, and saves it to a file /// From a5f517ca7c7c9d563eb104f4ac53e2538532789f Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 29 Sep 2019 01:34:51 +0300 Subject: [PATCH 2/2] =?UTF-8?q?-=20attempt=20=E2=84=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs | 6 ++++-- ScreenAssistant/Games/ApLeg/WeaponAL.cs | 2 +- ScreenAssistant/Games/ApLeg/Weapons/Havoc.cs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs b/ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs index 376c200..9dbd584 100644 --- a/ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs +++ b/ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs @@ -30,7 +30,8 @@ public static Image CaptureScreenRelatively(float startX, float endX, float star { if (fullScreen) { - return CaptureWindowFromGraphics(User32.GetForegroundWindow(), startX, endX, startY, endY); + return CaptureWindow(User32.GetDesktopWindow(), startX, endX, startY, endY); + //return CaptureWindowFromGraphics(User32.GetForegroundWindow(), startX, endX, startY, endY); } return CaptureWindow(User32.GetForegroundWindow(), startX, endX, startY, endY); @@ -63,7 +64,7 @@ internal static Image CaptureWindow(IntPtr handle, float startX, float endX, flo IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap); // bitblt over GDI32.BitBlt(hdcDest, 0, 0, (int)((endX - startX) * width / 100), (int)((endY - startY) * height / 100), - hdcSrc, (int)(startX * width / 100), (int)(startY * height / 100), GDI32.SRCCOPY); + hdcSrc, (int)(startX * width / 100), (int)(startY * height / 100), GDI32.SRCCOPY | GDI32.CAPTUREBLT); // restore selection GDI32.SelectObject(hdcDest, hOld); // clean up @@ -137,6 +138,7 @@ public static void CaptureScreenToFile(string filename, ImageFormat format) /// private class GDI32 { + public const int CAPTUREBLT = 0x40000000; public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter [DllImport("gdi32.dll")] diff --git a/ScreenAssistant/Games/ApLeg/WeaponAL.cs b/ScreenAssistant/Games/ApLeg/WeaponAL.cs index 5f529ff..6d1aa04 100644 --- a/ScreenAssistant/Games/ApLeg/WeaponAL.cs +++ b/ScreenAssistant/Games/ApLeg/WeaponAL.cs @@ -13,7 +13,7 @@ public enum WeaponAL { [WeaponData("", 0, " ")] Unknown = 1 << 0, - [WeaponData("Havoc", 5, "HAVUC")] + [WeaponData("Havoc", 4, "HAVUC")] Havoc = 1 << 1, [WeaponData("Triple take", 4)] TripleTake = 1 << 2, diff --git a/ScreenAssistant/Games/ApLeg/Weapons/Havoc.cs b/ScreenAssistant/Games/ApLeg/Weapons/Havoc.cs index 81d7b0d..a4f1f71 100644 --- a/ScreenAssistant/Games/ApLeg/Weapons/Havoc.cs +++ b/ScreenAssistant/Games/ApLeg/Weapons/Havoc.cs @@ -11,7 +11,7 @@ public Havoc(string name, double burstSeconds, string recognizedName, int numOfM public override double AdjustMouse(int shotNumber) { - var notOffsettingDelay = this.GetModuleType(4) == WeaponModuleType.Legendary ? 0 : 6; + var notOffsettingDelay = this.GetModuleType(3) == WeaponModuleType.Legendary ? 0 : 6; if (shotNumber > notOffsettingDelay) { this.AdjustmentCoefficient = CalculateAdjustment(shotNumber, 40);